7

Is there a reliable way to open a new window in JavaScript and keep focus on the current window, provided we can have code in both windows? If not possible in all browsers, then being able to do it in some at least, would still be useful.

I have tried the following :

1.

var handle = window.open(...);
handle.blur();
window.focus();

In the opened window that should lose focus :

window.addEventListener('load', (event) => {
  window.blur();
  window.opener.focus();
});

But it doesn't seem to work in Chrome, Safari and Firefox.

t_tsekov
  • 177
  • 3
  • 11
  • 1
    Does this answer your question? [Open a new tab with javascript but stay on current tab](https://stackoverflow.com/questions/6213807/open-a-new-tab-with-javascript-but-stay-on-current-tab) – Kinglish Jun 24 '21 at 00:42
  • I am specifically interested in a new window, not a new tab. Since there might be differences in browser behavior, it does not. – t_tsekov Jun 24 '21 at 00:47
  • Does this answer your question? [Making a window pop under in chrome](https://stackoverflow.com/questions/4261784/making-a-window-pop-under-in-chrome) – esqew Jun 24 '21 at 00:50
  • Browsers block popunders – Matt Jun 24 '21 at 01:06
  • None of the approaches in this thread seems to work now. @ esqew – t_tsekov Jun 24 '21 at 08:45

0 Answers0