Opera: Can't get load event from window.open()

2019-02-26 02:28发布

问题:

var openedWindow = window.open("test.html", "title");

openedWindow.addEventListener("load", function() {
    console.log("received load event");
}, false);

I want to get the load event from an opened window. The code above works, but the callback function does not get called in Opera 11.62 (works on other browser).

EDIT: It works when i register the event after 0ms timeout:

var openedWindow = window.open("test.html", "title");

window.setTimeout(function() {
    openedWindow.addEventListener("load", function() {
        console.log("received load event");
    }, false);
}, 0);

回答1:

this seems to be a known bug in Opera - I've pushed the internal bug report (CORE-46278) a little bit forward.

The only workaround I can think of is adding callbacks from the popup contents - type opener.popupLoaded(). This may however offer a performance advantage too - you can start interacting with the popup when its script environment is ready and the script you want to talk to is running, rather than waiting for the load event.