0

I have a problem with IE11: I open new window in js and bind to it an event in old window. But it isn't work when old window is inactive. When I fast switch tabs -it work and also it work when I use window.blur to remove focus from new tab.

There is my code:

var win = window.open(url);
//win.blur(); trash solution
this.bindLoadEvent(win, function() {
     element.invoke();
});

bindLoadEvent: function (win, handler) {
     if (win.addEventListener) {
            win.addEventListener('load', handler, true);
     } else {
            win.attachEvent('onload', handler);
     }
}

It's seems like IE doesn't fire events in inactive tabs.

P.S. Also I tested it in Firefox and Chrome - it's work great.

gado
  • 33
  • 1
  • 7
  • I found this article: https://msdn.microsoft.com/en-us/library/ms537636(v=vs.85).aspx but I still can 't fire event – gado Jan 26 '17 at 11:20

1 Answers1

0

Load event may occur before you attach handler.

Try to check whether window already loaded before you attach event handler:

bindLoadEvent = function (win, handler) {
    if (win.document.readyState === "complete") {
      setTimeout(handler, 0);
    } else if (win.addEventListener) {
      win.addEventListener('load', handler, true);
    } else {
      win.attachEvent('onload', handler);
    }
  };

For more information check How to detect if document has loaded (IE 7/Firefox 3) and Detecting the onload event of a window opened with window.open questions.

Community
  • 1
  • 1
Leonid Vasilev
  • 11,910
  • 4
  • 36
  • 50