Open A New Tab With Javascript But Stay On Current Tab Using Javascript
Solution 1:
As confirmed in both: source1source2
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.
Solution 2:
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
Solution 3:
try this code
window.open(url,'_blank');
Post a Comment for "Open A New Tab With Javascript But Stay On Current Tab Using Javascript"