How can we know when pop-up window url is loaded (window.open)?
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开发者_C百科 in the parent window? I cannot change anything in the page I am opening in pop-up, because it belongs to another website.
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.
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 */ };
}
精彩评论