IE: window.open returning null

2019-07-22 17:36发布

问题:

on a click event, I am running this code:

win = window.open(a.href);
i = setInterval(function () {
    if (win.closed) {
        /* do things */
    }
}, 250);

this works fine in Firefox and Chrome, but in IE (9) it says that win is undefined or null. How can I work around this?

EDIT: The window IS opened correctly in IE, it's just that a reference to it is not saved in win like it is in Firefox/Chrome.

回答1:

Add name to the window:

win = window.open(a.href, "myWin");