使用 Javascript 在 IE7/8 中加载 iframe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6455834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iframe onload in IE7/8 with Javascript
提问by Chris Tonkinson
I have an iframe loading into a parent page. The iframe contains a sequence of forms, and I'd like to take action on the parent page every time the iframe content in reloaded (ie, after a form is submitted in the iframe content). The current code is located on the parent page and works in all the big players except IE (I'm only concerned with IE 7 & 8).
我有一个 iframe 加载到父页面中。iframe 包含一系列表单,每次重新加载 iframe 内容时(即,在 iframe 内容中提交表单之后),我都想在父页面上执行操作。当前代码位于父页面上,适用于除 IE 之外的所有大型播放器(我只关心 IE 7 和 8)。
var iframe = document.getElementById('theiframe');
function refresh( ) {
alert('foo');
}
if (iframe.attachEvent) iframe.attachEvent('onload', refresh);
else iframe.onload = refresh;
What am I missing that would prevent this from being effective in IE?
我错过了什么会阻止它在 IE 中有效?
采纳答案by Joe
Replace:
代替:
iframe.onload = refresh
with:
和:
iframe.attachEvent('load', refresh, false);
清除任何混淆:
var iframe = document.getElementById('theiframe');
function refresh( ) {
alert('foo');
}
if (iframe.attachEvent) iframe.attachEvent('onload', refresh);
else iframe.addEventListener('load', refresh, false)
回答by Mic
You can call it from the iframe
by calling parent.refresh()
when you are done with a submit.
您可以在完成提交后iframe
通过调用来调用它parent.refresh()
。