简体   繁体   English

动态更改 iframe 的负载

[英]dynamically change onload for an iframe

I have a page containing a couple of <iframe> tags.我有一个包含几个<iframe>标签的页面。 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.我有以下代码在 FF、Safari、Chrome、Opera 中运行良好,但 IE (8) 拒绝遵守。

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.我一直在使用类似的东西来设置<input>元素的onchange ,这在我测试过的所有浏览器中都很好用,包括 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.所以我想这与我获取框架元素/object 的方式有关。

I've also tried frames['myiframe'] but with no success.我也尝试过frames['myiframe']但没有成功。

Thanks for your help!谢谢你的帮助!

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) (我在 IE9 上尝试了打开 IE8 模式)
If it does not work for you, try this:如果它不适合你,试试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM