简体   繁体   中英

How can I know when a window popup is loaded?

Tried this my code:

var w = window.open("http://www.jsfiddle.net");

if (w) {
    w.onload = function() {
        $('#complete').html("finished");
    };
}

but I'm far away from by target. I want to write "finished" in the div when the window is loaded. How can I do it?

If you want to control from parent you could use ajax to grab the html and inject it into the popup window.

$.ajax({
   url:"somepage.html",
   success:function(html) {
     $('#complete').html("finished");
     var popup = window.open("");
     var doc = popup.document;
     doc.write(html);
   }
});

Though if the child page has scripts that depend on onload they may not fire,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM