Apparently it is not possible to open a tab in the background, I found this reply, the test:
function openNewBackgroundTab(url)
{
var a = document.createElement("a");
a.href = url;
var evt = document.createEvent("MouseEvents");
//the tenth parameter of initMouseEvent sets ctrl key
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0,
true, false, false, false, 0, null);
a.dispatchEvent(evt);
}
<a href="https://answall.com" onclick="openNewBackgroundTab('https://www.google.com');">Redireiciona para a Home</a>
However didn’t work, I believe Chrome has removed this capability.
I think it is not possible at all to do this, because that would be to control the machine/decision of the end user and actually put yourself in its place, you would like it to be opened?
The control of where the page will open should be the decision of the user I believe, maybe I should change the approach.
Can you describe the goal? It is not very clear why to open another page without directing the user. Why the user would click on a link like this?
– Woss
It seems the procedure that these boring ad sites do, click to see the video and open 500 pages in the background.
– Raizant
@Knautiluz, that :) kkk
– David
Let’s go continue this discussion in chat.
– Guilherme Nascimento
Now I understand (I think). You have no control over this, who decides whether the new tab will open in the background or not is the browser and user settings.
– bfavaretto
So@bfavaretto, adult content sites do this, so I believe it’s possible, I think
– David
They have new windows opened, but the browser defines whether it will open as a window, as a tab, and whether it will focus or keep in the background.
– bfavaretto