javascript 如何使用 HTML/JS 在 chrome 中打开一个新标签页?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5495328/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 17:23:31  来源:igfitidea点击:

How do you open a new tab in chrome using HTML/JS?

javascripthtmlgoogle-chrometabs

提问by liamzebedee

I tried this code

我试过这个代码

window.open('page2.html','_newtab');

window.open('page2.html','_newtab');

And all it opened was a new window. How do I open a new tab?

它打开的只是一个新窗口。如何打开新标签页?

回答by Dave

This is a browser setting and not something you can control with code. In my browser, your "window.open" will open a new tab, because that's what I have mine set up to do. In others' browsers, it might open a new window.

这是浏览器设置,不是您可以用代码控制的。在我的浏览器中,您的“window.open”将打开一个新选项卡,因为这是我的设置。在其他人的浏览器中,它可能会打开一个新窗口。

回答by Carl Smith

You can do this easily. See the answer here.

你可以很容易地做到这一点。请参阅此处的答案。

回答by Pascal MARTIN

I don't think you can, from HTML / Javascript, indicate that a page should be opened in a new tab.

我认为您不能从 HTML/Javascript 中指示应在新选项卡中打开页面。

(In fact, your page might be opened to a new window, or to a new tab, depending on the configuration of the browser)

(实际上,您的页面可能会打开到新窗口或新选项卡,具体取决于浏览器的配置)