Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 728
inZa Avatar asked Nov 07 '22 15:11

inZa


1 Answers

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

window.opener.document.createEvent('CustomEvent');
like image 174
Benjamin Araya Avatar answered Nov 15 '22 13:11

Benjamin Araya