为什么 InternetExplorer 11 不在非活动选项卡中触发事件?
Why InternetExplorer 11 doesn't fire events in inactive tab?
我的 IE11 有问题:我在 js 中打开新的 window,并在旧的 window 中绑定一个事件。但是当 old window 处于非活动状态时它不起作用。当我快速切换标签时 - 它工作并且当我使用 window.blur 从新标签中删除焦点时它也工作。
这是我的代码:
var win = window.open(url);
//win.blur(); trash solution
this.bindLoadEvent(win, function() {
element.invoke();
});
bindLoadEvent: function (win, handler) {
if (win.addEventListener) {
win.addEventListener('load', handler, true);
} else {
win.attachEvent('onload', handler);
}
}
IE 似乎不会在非活动选项卡中触发事件。
P.S。我还在 Firefox 和 Chrome 中测试了它 - 它工作得很好。
加载事件可能会在您附加处理程序之前发生。
在附加事件处理程序之前尝试检查 window 是否已经加载:
bindLoadEvent = function (win, handler) {
if (win.document.readyState === "complete") {
setTimeout(handler, 0);
} else if (win.addEventListener) {
win.addEventListener('load', handler, true);
} else {
win.attachEvent('onload', handler);
}
};
有关详细信息,请查看 How to detect if document has loaded (IE 7/Firefox 3) and Detecting the onload event of a window opened with window.open 个问题。
我的 IE11 有问题:我在 js 中打开新的 window,并在旧的 window 中绑定一个事件。但是当 old window 处于非活动状态时它不起作用。当我快速切换标签时 - 它工作并且当我使用 window.blur 从新标签中删除焦点时它也工作。
这是我的代码:
var win = window.open(url);
//win.blur(); trash solution
this.bindLoadEvent(win, function() {
element.invoke();
});
bindLoadEvent: function (win, handler) {
if (win.addEventListener) {
win.addEventListener('load', handler, true);
} else {
win.attachEvent('onload', handler);
}
}
IE 似乎不会在非活动选项卡中触发事件。
P.S。我还在 Firefox 和 Chrome 中测试了它 - 它工作得很好。
加载事件可能会在您附加处理程序之前发生。
在附加事件处理程序之前尝试检查 window 是否已经加载:
bindLoadEvent = function (win, handler) {
if (win.document.readyState === "complete") {
setTimeout(handler, 0);
} else if (win.addEventListener) {
win.addEventListener('load', handler, true);
} else {
win.attachEvent('onload', handler);
}
};
有关详细信息,请查看 How to detect if document has loaded (IE 7/Firefox 3) and Detecting the onload event of a window opened with window.open 个问题。