Search code examples
javascriptreactjsbuttondom-eventssetstate

Adding focus to the current tab


I am trying to open up a page in a new tab, but it always makes the newly opened tab active. I want the current tab to be active and the new page should open on a background. I am trying to do it using a function without any <a> tag.

What I have tried:

navigate = () => {
    window.open("http://www.google.com", "_blank");
    window.focus();
 }

<button onClick={this.navigate}>Navigate</button>

Solution

  • That's not possible as far as I know, that's controlled by the Browser and not by your code.