Iframe onload in IE7 / 8 with Javascript

I have an iframe loaded on the parent page. The IFrame contains a sequence of forms, and I would like to take action on the parent page every time the iframe content is reloaded (i.e., after the form is presented in the iframe content). The current code is located on the parent page and works in all major players except IE (I'm only interested in IE 7 and 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 so that this does not help IE?

+6
source share
2 answers

Replace:

 iframe.onload = refresh 

from:

 iframe.attachEvent('load', refresh, false); 


To eliminate any confusion:
 var iframe = document.getElementById('theiframe'); function refresh( ) { alert('foo'); } if (iframe.attachEvent) iframe.attachEvent('onload', refresh); else iframe.addEventListener('load', refresh, false) 
+4
source

You can call it from an iframe by calling parent.refresh() when you're done with the submit.

+1
source

Source: https://habr.com/ru/post/891218/


All Articles