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.
Need to reference the originating window or else it rejects the event
window.opener.document.createEvent('CustomEvent');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With