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!

Sorin Buturugeanu
  • 1,782
  • 4
  • 19
  • 32

1 Answers1

6

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); 
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
  • 2
    Read more here: [http://stackoverflow.com/.../iframe-onload-in-ie7-8-with-javascript](http://stackoverflow.com/questions/6455834/iframe-onload-in-ie7-8-with-javascript) – Derek 朕會功夫 Jul 20 '11 at 18:22