1

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.

4

2 回答 2

1

使用 jQuery 从父级触发事件

var o = window.opener; 
o.$(o.document).trigger("myEvent");
于 2015-03-10T16:09:14.103 回答
0

我使用 hashchange 事件作为解决方法,因为 IE11 通常不会向 window.opener 触发事件。

window.opener.window.location.hash = (new Date()).getTime().toString() + '&myEvent=true';
window.close();

开瓶器侧

window.addEventListener('hashchange', function(){
    if (window.location.hash.indexOf('&myEvent=true') > -1) {
        // fire event on opener
    }
}
于 2019-09-26T12:56:31.727 回答