3

I have a page containing a couple of <iframe> tags. I want to change their onload actions dynamically. I have the following code that works fine in FF, Safari, Chrome, Opera, but IE (8) refuses to comply.

document.getElementById('myiframe').onload = function() {
    return function() { file_onLoad(data); }
}();

I've been using something similar for setting the onchange of an <input> element and this works well in all the browsers I've tested, including IE.

document.getElementById('myinput').onchange = function() {
    return function() { file_onChange(data); }
}();

So I guess it has something to do with the way I'm getting the frame element / object.

I've also tried frames['myiframe'] but with no success.

Thanks for your help!

1 Answer 1

7

It works fine on mine...
I tried:

function whatever(){
    document.getElementById('myiframe').src="http://www.google.com/"
    document.getElementById('myiframe').onload = function() {
        return function() { alert("Done."); }
    }();
}

and it works. (I tried on IE9 with IE8 mode turned on)
If it does not work for you, try this:

document.getElementById('myiframe').addEventListener('load', file_onLoad, false); 
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.