Reputation: 13
I have a problem since few days.
On firefox my code works but not on IE. I have a window which open new window with window.open; In this new window, I do what I want and after that I would like to update a specific part on parent window. On parent window, I had :
$(document).on('myEvent', doThis);
And on the second window I had this (I don't want to use other library like jQuery if is possible) :
var event = new CustomEvent("myEvent");
window.opener.document.dispatchEvent(event);
window.close();
On Firefox the code seems Okay but on IE it doesn't work; I've tried to add a CustomEvent polyfill (because I undestand IE doesn't implement CustomEvent), but I have new problem... IE doesn't like my :
window.opener.document.dispatchEvent(event);
How can I send an event on my "opener" (or parent) window when I finnish to do what I want in new window which was opened by my "opener" (or parent) window ?
Thx.
Upvotes: 1
Views: 1749
Reputation: 104
I use hashchange event as a workaround since IE11 doesn't fire event to window.opener typically.
window.opener.window.location.hash = (new Date()).getTime().toString() + '&myEvent=true';
window.close();
Opener side
window.addEventListener('hashchange', function(){
if (window.location.hash.indexOf('&myEvent=true') > -1) {
// fire event on opener
}
}
Upvotes: 0
Reputation: 207531
Trigger the event from the parent with jQuery
var o = window.opener;
o.$(o.document).trigger("myEvent");
Upvotes: 1