Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting the onload event of a window opened with window.open

 window.popup = window.open($(this).attr('href'), 'Ad', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');  $(window.popup).onload = function()         {                 alert("Popup has loaded a page");         }; 

This doesn't work in any browser I've tried it with (IE, Firefox, Chrome). How can I detect when a page is loaded in the window (like an iframe onload)?

like image 720
Christopher Tarquini Avatar asked Jun 13 '10 02:06

Christopher Tarquini


1 Answers

var myPopup = window.open(...); myPopup.addEventListener('load', myFunction, false);

If you care about IE, use the following as the second line instead:

myPopup[myPopup.addEventListener ? 'addEventListener' : 'attachEvent'](   (myPopup.attachEvent ? 'on' : '') + 'load', myFunction, false );

As you can see, supporting IE is quite cumbersome and should be avoided if possible. I mean, if you need to support IE because of your audience, by all means, do so.

like image 173
Delan Azabani Avatar answered Sep 22 '22 20:09

Delan Azabani