benekastah
benekastah

Reputation: 5711

onload event not fired more than once for child windows

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

Answers (1)

Diodeus - James MacFarlane
Diodeus - James MacFarlane

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

Related Questions