1

is it possible return focus on tab parent using javascript? I read some threads about this problem, but i didn't find solutions. I tried

window.opener.parent.focus()

and

window.opener.focus();

but it doesn't work. Can someone help me?

Thanks

Riccardo Gai
  • 421
  • 1
  • 6
  • 19

1 Answers1

1

Generally, you cannot do this inside a web page. Because it's the user's choice which tab/window she wants to focus on and browsers such as firefox and chrome respect such choices by providing configs to open new tabs in the background or not. But under several very special cases, you may still achieve this.

  1. If you want to open a new tab and return focus immediately, you can try to simulate a 'ctrl+click' event on a link to open the tab on the background. Refer to this thread Open a new tab in the background?(Only for chrome, API may already changed. So it may only works on an obsoleted version)

  2. If you are shipping with an extension, do it in the extension code. For example: in chrome extension.

  3. If your script is for a customized browsers which you have control on / you can affect the design, you can implement the function in the browser side and expose an API for your script.

Community
  • 1
  • 1