Home > Software engineering >  window.open(url,'_blank') opens in background tab, not getting focus
window.open(url,'_blank') opens in background tab, not getting focus

Time:11-18

In Chromium-based browsers version 107 I notice opening a new tab with window.open does not give focus to the new tab. Previous it did, and in Firefox it still does

//code before
{
  let url = "https://google.com";
  window.open(url,"_blank");
}

When I run the window open in the console it does give the tab focus. Also giving a return true or adding event.preventDefault() or event.stopImmediatePropagation() before doe not work.

However, if I move the test code to the top of the code block, it does work.

Is Anyone aware of a change in Chromium, or a constraint that will open the new page in the background?

CodePudding user response:

Yes, it will automatically open a new page in the background. Unfortunately, there is no way around this.

Sorry :(

CodePudding user response:

My Chrome is 107.0.5304.107.
Doing this will create a new tab and give it focus.

<html>

<body>
  <script>
    let url = "https://google.com";
    window.open(url, "_blank");
  </script>
</body>

</html>

Please post your html and JavaScript.

  • Related