Reputation: 5711
Consider this case:
var openWindow = function (name) {
var win = window.open("/", name);
document.write("Opening window: " + name + "<br />");
win.onload = function () {
document.write("Opened window: " + name + "<br />");
};
};
var openAsdf = openWindow.bind(null, "asdf");
openAsdf();
setTimeout(openAsdf, 3000);
(See this jsfiddle)
Don't close the window before the three seconds is up. You will notice the second load event isn't called (even though the page in the window seems to refresh). Why not? And how can I determine when an existing window refreshes, or is called again?
Upvotes: 1
Views: 887
Reputation: 114417
Hook up your onload event BEFORE you open the window. By the time it opens it may have already fired.
See: Add onload function to an opening window
Upvotes: 1