Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a new tab with javascript but stay on current tab

Is it possible to open a new tab in Firefox (in background) using window.open("http://www.google.com") function, and remain the current tab?

Thanks for any help

like image 953
Daniel H Avatar asked Jun 02 '11 11:06

Daniel H


People also ask

Is it possible to open a new tab but stay on the current tab?

Yes, either change the browser preferences or use whatever key and click combination is required for that browser to open the link in a new tab but keep focus on the current on.

How do I open a new tab with JavaScript?

To open a new tab, we have to use _blank in the second parameter of the window. open() method. The return value of window. open() is a reference to the newly created window or tab or null if it failed.

Is there a way to open links in a new tab without switching to that tab?

1) select "open link in new background tab" from the context menu (second choice), 2) use middle-click on the link with your mouse; 3) use Ctrl+leftclick on the link with your mouse, 4) designate a mouse gesture to open a background tab when you perform it over a link.


2 Answers

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 is:

browser.tabs.loadDivertedInBackground=true
like image 151
dogbane Avatar answered Sep 17 '22 13:09

dogbane


Whether or not to focus a new tab when it is opened is a browser setting and not something that you can control.

Opening links in a new tab at all (rather than a separate window) is a browser setting too, so you're facing an uphill battle with this one.

Basically, leave it up to the user to decide how they want to open links.

like image 35
Town Avatar answered Sep 21 '22 13:09

Town