Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript appending onload to a popup window

I'm trying to append an onload event to a popup window in the following manner:

var explorerWindow = window.open(PARAMS...);
explorerWindow.onload = function() {window.opener.unlockObj(id);}

The idea is to make the button that generates the popup window readonly, making it usable again once the popup window has loaded all of its contents. However, the event doesn't seem to be firing at all. I even changed it to the following and got nothing:

explorerWindow.onload = function() {alert("bloop");}

Is there something terribly wrong with my syntax or am I missing something else entirely? Also, I'm using JQuery if there are any appropriate gems there that will help in this situation. I tried the following with similar results, but I'm not so sure I got the call right:

$(explorerWindow).load(function() {alert("bloop");});

Any help is greatly appreciated.

like image 526
Hypnotic Meat Avatar asked Nov 25 '22 20:11

Hypnotic Meat


1 Answers

This won't work in all browsers. I'd suggest putting the onload handler in the document loaded into the new window and have that call out to the original page:

window.onload = function() {
    opener.doStuff();
}
like image 153
Tim Down Avatar answered Mar 02 '23 07:03

Tim Down