views:

405

answers:

2

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.

+1  A: 

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();
}
Tim Down
A: 

I actually managed to get it working in the browsers I have to support with the following:

explorerWindow.onload = new function() { explorerWindow.opener.unlockObj(id); }

Thanks for the reply though Tim.

Hypnotic Meat
Really? I suggest you test that carefully. Thanks to the use of `new`, that will be calling `unlockObj(id)` immediately (not waiting for the new window to load first) and is assigning an object rather than a function to `explorerWindow.onload`, which will do nothing (at least, nothing useful). That line will be practically equivalent to just calling `unlockObj(id);`.
Tim Down