javascript - IE 11 Window.opener.dispatchEvent 抛出 SCRIPT87 : Invalid Argument

标签 javascript events internet-explorer-11

我有打开另一个窗口的父窗口。在子窗口中,我试图将事件发送到开启者。我的代码如下所示:

export function taskClose(opener: string) {
if (!window.opener || window.opener === window || window.opener.closed) {
        redirectToPath(opener);
        return;
    }

var updateEvent;
if (typeof(Event) === 'function') {
    updateEvent = new Event('inboxNeedUpdate');
}else {
    updateEvent = document.createEvent('CustomEvent');
    updateEvent.initCustomEvent('inboxNeedUpdate', false, false, undefined);
}
window.opener.dispatchEvent(updateEvent);
window.close();}

我想知道如何正确地将事件分派(dispatch)到开启窗口。
此代码在 Chrome 和 FF 中正确工作。

最佳答案

需要引用原始窗口,否则它会拒绝事件

window.opener.document.createEvent('CustomEvent');

关于javascript - IE 11 Window.opener.dispatchEvent 抛出 SCRIPT87 : Invalid Argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46889936/

相关文章:

javascript - 在 Protractor 中对多个按钮使用循环

java - 当类型未知时,如何避免使用原始类型并使用泛型?

javascript - IE 9 和 IE 最新版本上 javascript 中的不同日期格式

javascript - 获取索引处没有元素的数组

JQuery "tap"事件触发两次

delphi - 调整表单大小,同时保持纵横比

html - 如何在 IE 的列中显示 ul 列表?

javascript - Angular2 数据在 IE11 中未绑定(bind)

JavaScript 代码在其他浏览器中完美运行,但在 ie11 中会破坏 AngularJS?

javascript - "JavaScript: The Good Parts"- 实现原型(prototype)方法的方式?