使用Javascript在IE7 / 8中加载iframe [英] iframe onload in IE7/8 with Javascript
本文介绍了使用Javascript在IE7 / 8中加载iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将iframe加载到父页面中。 iframe包含一系列表单,每次重新加载iframe内容时(即,在iframe内容中提交表单之后),我都希望在父页面上执行操作。当前代码位于父页面上,适用于IE以外的所有大型播放器(我只关注IE 7和8)。
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).
var iframe = document.getElementById('theiframe');
function refresh( ) {
alert('foo');
}
if (iframe.attachEvent) iframe.attachEvent('onload', refresh);
else iframe.onload = refresh;
我错过了哪些会阻止它在IE中有效?
What am I missing that would prevent this from being effective in IE?
推荐答案
替换:
iframe.onload = refresh
with:
iframe.attachEvent('load', refresh, false);
清除任何混淆:
To clear any confusion:
var iframe = document.getElementById('theiframe');
function refresh( ) {
alert('foo');
}
if (iframe.attachEvent) iframe.attachEvent('onload', refresh);
else iframe.addEventListener('load', refresh, false)
这篇关于使用Javascript在IE7 / 8中加载iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文