1

I want script to open in new tab url without focusing on it. I tried:

window.open("https://www.google.com/").blur();
window.focus();

But it opens a new tab and focuses on google.com not on site with script. What's wrong?

edit:

This Open a new tab in the background? is not resolving my question. Answer is too old and doesn't work anymore! Admins please read bold text: "UPDATE: By version 41 of Google Chrome, initMouseEvent seemed to have a changed behavior, and so this answer no longer works."

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Stack1233
  • 85
  • 5
  • This is not possible in Google Chrome anymore. The behaviour is strictly controlled by the browser. – squidee_ Jun 24 '22 at 22:59
  • @squidee_ than how some advertisments open new tabs on background? – Stack1233 Jun 24 '22 at 23:05
  • If you are talking about popups in a seperate window, this is still possible. – squidee_ Jun 24 '22 at 23:06
  • @squidee_ yeah. How to create so they will open on background? – Stack1233 Jun 24 '22 at 23:11
  • Try this guide. [JavaScript.Info](https://javascript.info/popup-windows#example-a-minimalistic-window) – squidee_ Jun 24 '22 at 23:15
  • @squidee_ sorry, I meant new tab not window – Stack1233 Jun 24 '22 at 23:22
  • tab != window ... – dippas Jun 24 '22 at 23:24
  • Could you send me a link where this happens? I've never experienced this. – squidee_ Jun 24 '22 at 23:30
  • @squidee_ it's local file. You can create blank html (or php if you have local server) file, add script tag and paste code from my question in it – Stack1233 Jun 24 '22 at 23:38
  • I mean a link from where you have seen this before. I don't believe this is possible in Google Chrome, and most likely not possible in other major browsers. – squidee_ Jun 24 '22 at 23:51
  • @squidee_ I've seen it long time ago in old browsers so I don't remember where. I believe that it was done with answer from this question https://stackoverflow.com/questions/10812628/open-a-new-tab-in-the-background but as solution is not working anymore - I'm trying to find out if there still is a way to do this. – Stack1233 Jun 24 '22 at 23:57
  • Unfortunatley, this is not possible in modern browser. And if you could even find a work around, it would be very inconsistent and wouldn't work in many other browser. – squidee_ Jun 25 '22 at 00:12
  • @squidee_ I've created solution. It's not have the same logic as I wanted but it does same thing. It opens new tab with same url and old tab is redirected to google.com. There is a code: https://onecompiler.com/javascript/3y84zcm63. – Stack1233 Jun 25 '22 at 14:26
  • The fact the accepted answer no longer works, doesn't mean your question isn't a duplicate. Maybe one of the other answers does work, or maybe someone needs to post an answer that this is no longer possible at all. – Mark Rotteveel Jun 27 '22 at 09:22

0 Answers0