Window open focus or active

I want to open the window in a new tab, but when I want this opening page to be active, not a new one. How can I do this ... Thanks a lot

my code looks something like this:

  <script language="javascript">
  window.open("http://www.google.ro");
  window.opener.location.focus();
  </script>
+3
source share
3 answers

To focus on a new window (but you don’t want this, and by default it will have focus):

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

I don’t think you can steal focus from new open tabs. I did not find an official statement about this, but all the articles that I found about this will talk about setting up the browser to open default tabs without focus.

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

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

Please note that when you open pop-ups, you can move the focus.

window.


: , 2 , , SO , , .

+4

...

var newWindow = window.open('http://www.google.ro', '_blank', 'height=300,width=300,menubar=0,status=0,toolbar=0', false);

window.focus();
+3

To return to the open window, try using window.focus(window.name);insteadwindow.opener.location.focus();

+1
source

Source: https://habr.com/ru/post/1780516/


All Articles