Search code examples
javascriptinternet-explorereventsdispatcheventwindow.opener

CustomEvent in IE with window.opener


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.


Solution

  • Trigger the event from the parent with jQuery

    var o = window.opener; 
    o.$(o.document).trigger("myEvent");