HTML:如何强制链接在新选项卡中打开,而不是在新窗口中打开

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

HTML: how to force links to open in a new tab, not new window

htmlcross-browsertabs

提问by Moon

I use target="_blank"to open links in a new tab. But in IE it opens a new window which is completely logical because that is what _blankis supposed to do.

我用来target="_blank"在新标签页中打开链接。但在 IE 中它会打开一个新窗口,这是完全合乎逻辑的,因为这_blank是应该做的。

And i don't know how target="_blank"behaves in other browsers.

而且我不知道target="_blank"在其他浏览器中的表现如何。

Is there something to force links to open in a new tab. If the browser supports tabs... else make a new window

是否有强制链接在新选项卡中打开的功能。如果浏览器支持标签...否则创建一个新窗口

回答by Moin Zaman

There is no way to do that as the author of the HTML that a browser renders. At least not yet that I know of. Its pretty much up to the browser and its settings / preferences that are set by users themselves.

作为浏览器呈现的 HTML 的作者,没有办法做到这一点。至少我所知道的还没有。它几乎取决于浏览器及其由用户自己设置的设置/首选项。

Also, you shouldn't impose this upon any user. A browser is the user's property. If a user wants to open all links in tabs or in new windows, then let the user do exactly that.

此外,您不应将此强加给任何用户。浏览器是用户的财产。如果用户想要在选项卡或新窗口中打开所有链接,那么让用户完全这样做。

It's good that we can't do certain things. target=_blankis still abused and popups have been done to death.

我们不能做某些事情是件好事。target=_blank仍然被滥用,弹出窗口已经被杀死。

回答by Martin

Since I fell into this old question and then found that it is now possible (maybe this css option wasn't available then), I just want to add an update on how it can be done:

由于我陷入了这个老问题,然后发现现在可以了(也许这个 css 选项当时不可用),我只想添加一个关于如何完成的更新:

<a href="[yourlink]" target="_blank" style="target-new: tab;">Google</a>

Here are the options for the target-new style:

以下是 target-new 样式的选项:

target-new: window | tab | none 

Didn't test the none option, maybe it uses the default browser setting.

没有测试 none 选项,也许它使用默认浏览器设置。

I confirmed this for Firefox and IE7-9.

我为 Firefox 和 IE7-9 确认了这一点。

回答by Quentin

No, there isn't.

不,没有。

回答by Nasruddin

I hope this will help you

我希望这能帮到您

window.open(url,'_newtab');

window.open(url,'_newtab');

回答by ericmotil

onclick="window.open(this.href,'_blank');return false;"

回答by ericmotil

a {
    target-name: new;
    target-new: tab;
}

The target-new property specifies whether new destination links should open in a new window or in a new tab of an existing window.

target-new 属性指定新的目标链接应该在新窗口中还是在现有窗口的新选项卡中打开。

Note: The target-new property only works if the target-name property creates a new tab or a new window.

注意:target-new 属性仅在 target-name 属性创建新选项卡或新窗口时才有效。

回答by Tiago

I didn't try this but I think it works in all browsers:

我没有尝试过,但我认为它适用于所有浏览器:

target="_parent"

target="_parent"

回答by Andrew W.

The way the browser handles new windows vs new tab is set in the browser's options and can only be changed by the user.

浏览器处理新窗口与新选项卡的方式在浏览器的选项中设置,只能由用户更改。

回答by dev_doctor

You can change the way Safari opens a new page in Safari > Preferences > Tabs > 'Open pages in tabs instead of windows' > 'Automatically'

您可以更改 Safari 在 Safari > 首选项 > 选项卡 > '在选项卡中打开页面而不是窗口' > '自动' 中打开新页面的方式

回答by Lucas Matos

You can set IE to open links in new tab, just go to the settings menu.

您可以将 IE 设置为在新选项卡中打开链接,只需转到设置菜单即可。