views:

35

answers:

2

I need to change the URL of the page in the pop-up as soon as it completes loading ( I am using window.open function call). Is there anyway I can find out when the page in pop-up has completed loading in the parent window? I cannot change anything in the page I am opening in pop-up, because it belongs to another website.

A: 

this seems pretty self-explanatory, but tell me if you need more explanation (or if it doesn't work, though it should...)

var winObj = window.open( /* lot of params */ );

if( !winObj )
{
    /* pop-up blocked! */
}
else
{
    winObj.onload = function( ){ /* do stuff here */ };
}
Dan Beam
Can you tie into window events even with the restrictions of the same origin policy?
Andy E
The pop-up URL I am opening is on a different domain, so I am getting error like below:Error: Permission denied for <file://> to set property Window.onload on <http://otherwebsite.com>.
exsource
+1  A: 

window.open returns a reference to that window's window object.

If the opened window is pointing to a URL on the same domain as the window opener, then it will have full access to that object just as it does it's own window object.

var w = window.open(url);

// If the window opened successfully (e.g: not blocked)
if ( w ) {
    w.onload = function() {
        // Do stuff
    };
}

The same origin policy applies here. If the URL of the opened window is on a different domain, then the opener will not have access to members of that window's reference.

Justin Johnson
+1 for saying the exact same thing as me (however, you didn't mention what `if ( w )` meant), :P
Dan Beam