Open a new tab with javascript but stay on current tab using javascript [duplicate]

Is it possible to open a new tab in browser using the window.open("http://www.google.com"); function, but open it in the background and remain on the current page?
When i Click in hyperlink the page will same but link will open in new tab…

I try this solution but it work only in Firefox link
but I want to do in all browsers.

As confirmed in both: source1
source2

there isn’t a function that works throughout all browsers. There are options for popups, but this isn’t a good idea as many use popup blockers.

To reiterate the first source, it’s a browser setting for each user to decide to open a new tab in the background, or not. And because users decide this in their browser settings you will get inconsistent experiences.

Try following may be helpful

<button id="open">open</button>

document.getElementById('open').onclick = function() {
    window.open('http://google.com');   
};

Note:
You can’t open tabs in the background using javascript because this is set in the user’s preferences in about:config, which you have no control over. The setting in about:config in Firefox is:

It is only possible if you will be generate the Click event with Already Pressed Control Key Dynamically.

e.g. Ctrl + Click will always open new tab and stay you on current tab.

browser.tabs.loadDivertedInBackground=true

try this code

 window.open(url,'_blank');


The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   Can global constants be declared in JavaScript?

Similar Posts