Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window opener focus, or active

Tags:

javascript

i want to open a window in a new tab, but when i want that opener page to be active, not the new one. How can i do this... Many thanks

my code is something like this :

  <script language="javascript">
  window.open("http://www.google.ro");
  window.opener.location.focus();
  </script>
like image 384
cosy Avatar asked Dec 29 '22 03:12

cosy


1 Answers

To give focus to the new window (but you don't want that, and it will probably have focus by default):

var newWindow = window.open("http://www.google.ro", '_blank');
newWindow.focus();

I don't think it's possible to steal the focus from the new opened tabs. I didn't find any official statement telling this, but all the articles I found on this subject talk about configuring your browser to open tabs by default without focus.

The only "solution" I could come up with is this one:

window.open("http://google.com", "_blank");
window.alert('Hello there! This is a message that annoys you, the user.');

Note that it is possible to shift focus when opening popups.

Learn more about the window object.

like image 51
Alin Purcaru Avatar answered Jan 08 '23 16:01

Alin Purcaru