开发者

iframe onload in IE7/8 with Javascript

开发者 https://www.devze.com 2023-03-15 10:18 出处:网络
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 subm

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 开发者_JAVA技巧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;

What am I missing that would prevent this from being effective in IE?


Replace:

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)


You can call it from the iframe by calling parent.refresh() when you are done with a submit.

0

精彩评论

暂无评论...
验证码 换一张
取 消