inZa
inZa

Reputation: 41

IE 11 Window.opener.dispatchEvent throws SCRIPT87: Invalid Argument

I have parent window which opening another window. In the child window I am trying to send event to the opener. My code look like this:

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();}

I would like to know how to correctly dispatch event to opener window. This code correctly works in Chrome and FF.

Upvotes: 4

Views: 662

Answers (1)

Benjamin Araya
Benjamin Araya

Reputation: 31

Need to reference the originating window or else it rejects the event

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

Upvotes: 1

Related Questions