开发者

Open a new tab with javascript but stay on current tab

开发者 https://www.devze.com 2023-03-10 09:19 出处:网络
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?

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


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


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.


Here's an idea:

<script>
function open_in_bg(c_url, n_url)
{
 window.open (n_url, "mywindow" );
 window.open (c_url+"#maintain_focus","_self");
}
</script>

<input type="button" onclick="open_in_bg('current_page_url', 'url_to_be_opened')" />


I know you said JavaScript, OP, but, I feel the heart of the matter for you is just opening the html links in and of themselves in a new tab.

In which case, simple add ' target="_blank" ' inside your link tags:

<a href="example.com" target="_blank"> random stuff</a> 
0

精彩评论

暂无评论...
验证码 换一张
取 消