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

发布于 2024-09-28 07:52:29 字数 219 浏览 4 评论 0原文

我使用 target="_blank" 在新选项卡中打开链接。但在 IE 中,它会打开一个新窗口,这是完全合乎逻辑的,因为这就是 _blank 应该做的事情。

我不知道 target="_blank" 在其他浏览器中的行为如何。

有什么可以强制链接在新选项卡中打开的吗?如果浏览器支持选项卡...否则创建一个新窗口

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 _blank is supposed to do.

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

好菇凉咱不稀罕他 2024-10-05 07:52:29

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

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

幸好我们不能做某些事情。 target=_blank 仍然被滥用,弹出窗口已经被消灭了。

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.

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=_blank is still abused and popups have been done to death.

酒绊 2024-10-05 07:52:29

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

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

以下是 target-new 的选项style:

target-new: window | tab | none 

没有测试none选项,可能它使用默认的浏览器设置。

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

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:

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

Here are the options for the target-new style:

target-new: window | tab | none 

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

I confirmed this for Firefox and IE7-9.

暮年慕年 2024-10-05 07:52:29

不,没有。

No, there isn't.

疏忽 2024-10-05 07:52:29

我希望这会对您有所帮助

window.open(url,'_newtab');

I hope this will help you

window.open(url,'_newtab');

不交电费瞎发啥光 2024-10-05 07:52:29

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

target="_parent"

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

target="_parent"

冷了相思 2024-10-05 07:52:29

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

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.

没企图 2024-10-05 07:52:29
onclick="window.open(this.href,'_blank');return false;"
onclick="window.open(this.href,'_blank');return false;"
时常饿 2024-10-05 07:52:29
a {
    target-name: new;
    target-new: tab;
}

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

注意:仅当 target-name 属性创建新选项卡或新窗口时,target-new 属性才起作用。

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.

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

泅人 2024-10-05 07:52:29

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

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

金兰素衣 2024-10-05 07:52:29

您可以设置 IE 在新选项卡中打开链接,只需进入设置菜单即可。

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

清眉祭 2024-10-05 07:52:29

在 Internet Explorer 中,单击工具 ->互联网选项。单击常规选项卡->选项卡 ->设置。选择“遇到弹出窗口时”->始终在新选项卡选项中打开弹出窗口。单击“确定”。

In Internet Explorer, click the Tools -> Internet Options. Click General tab -> Tabs -> Settings. Choose "When a pop-up is encountered"-> Always open pop up in new tab option. Click OK.

意犹 2024-10-05 07:52:29

这是可能的!

这似乎会覆盖浏览器设置。希望它对你有用。

<script type="text/javascript">
// Popup window code
function newPopup(url) {
    popupWindow = window.open(url,'popUpWindow1','height=600,width=600,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>

<body>
  <a href="JavaScript:newPopup('http://stimsonstopmotion.wordpress.com');">Try me</a>
</body>

It is possible!

This appears to override browser settings. Hope it works for you.

<script type="text/javascript">
// Popup window code
function newPopup(url) {
    popupWindow = window.open(url,'popUpWindow1','height=600,width=600,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>

<body>
  <a href="JavaScript:newPopup('http://stimsonstopmotion.wordpress.com');">Try me</a>
</body>
入画浅相思 2024-10-05 07:52:29

简单地使用“target=_blank”将尊重用户/浏览器对是否使用选项卡或新窗口的偏好,这在大多数情况下是“做正确的事情”。

如果您指定新窗口的尺寸,某些浏览器将使用它作为需要特定尺寸的指示符,在这种情况下,将始终使用新窗口。 堆栈溢出代码示例 堆栈溢出

Simply using "target=_blank" will respect the user/browser preference of whether to use a tab or a new window, which in most cases is "doing the right thing".

If you specify the dimensions of the new window, some browsers will use this as an indicator that a certain size is needed, in which case a new window will always be used. Stack overflow code example Stack Overflow

椵侞 2024-10-05 07:52:29

尝试使用像这样的 javascript 函数

Html:

<a href="javascript:void(0)" onclick="open_win()">Target</a>

Javascript:

<script>
function open_win() 
{
window.open("https://www.google.co.in/");
}
</script>

Try with javascript function like this

Html:

<a href="javascript:void(0)" onclick="open_win()">Target</a>

Javascript:

<script>
function open_win() 
{
window.open("https://www.google.co.in/");
}
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文