使用 javascript 打开一个新标签,但留在当前标签上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6213807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open a new tab with javascript but stay on current tab
提问by Daniel H
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?
是否可以使用window.open("http://www.google.com")
功能在 Firefox(在后台)中打开一个新选项卡,并保持当前选项卡?
Thanks for any help
谢谢你的帮助
采纳答案by dogbane
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:
您无法使用 javascript 在后台打开选项卡,因为这是在 中的用户首选项中设置的about:config
,您无法控制。设置是:
browser.tabs.loadDivertedInBackground=true
回答by Anze Jarni
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')" />
回答by Town
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.
基本上,由用户决定他们想要打开链接的方式。
回答by Eleanor Zimmermann
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.
我知道你说的是 JavaScript,OP,但是,我觉得对你来说问题的核心只是在新标签中打开 html 链接。
In which case, simple add ' target="_blank" ' inside your link tags:
在这种情况下,只需在链接标签中添加 ' target="_blank" ':
<a href="example.com" target="_blank"> random stuff</a>