简体   繁体   中英

window opener focus, or active

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>

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.

This works for me...

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

window.focus();

To give back focus to the opener window, try using window.focus(window.name); instead of window.opener.location.focus();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM