HTML:如何强制链接在新标签页打开,而不是新窗口[复制]

时间:2022-05-04 21:16:56

This question already has an answer here:

这个问题已经有了答案:

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

我使用target="_blank"在一个新的标签中打开链接…但在IE中,它打开了一个全新的窗口,这是完全符合逻辑的,因为这就是_blank应该做的事情,我不知道target="_blank"在其他浏览器中的行为……是否有什么东西可以强制链接在新标签页打开。如果浏览器支持标签……否则新建一个窗口

14 个解决方案

#1


74  

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

我们不能做某些事是好事。target=_blank仍然被滥用,弹出窗口已经被执行到死亡。

#2


40  

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: 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上证实了这一点。

#3


8  

No, there isn't.

不,没有。

#4


5  

I hope this will help you

我希望这能对你有所帮助

window.open(url,'_newtab');

window.open(url,“_newtab”);

#5


1  

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.

浏览器处理新窗口和新标签的方式是在浏览器的选项中设置的,只能由用户修改。

#6


1  

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

我没有尝试,但我认为它在所有浏览器中都适用:

target="_parent"

目标= " _parent "

#7


1  

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

#8


1  

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-name属性创建新选项卡或新窗口时,才可以使用target-new属性。

#9


0  

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

你可以改变Safari打开新页面的方式在Safari >首选项>选项卡> '在选项卡中打开页面而不是windows' > '自动'

#10


0  

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

你可以将IE设置为在new选项卡中打开链接,只需进入设置菜单。

#11


0  

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.

在Internet Explorer中,单击工具-> Internet选项。点击常规选项卡->选项卡->设置。选择“当弹出时”->总是打开弹出在新的标签选项。单击OK。

#12


0  

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>

#13


0  

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".

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

  • IE9+ Default: Tab : Preference: "Always open pop-ups in a new tab"
  • IE9+默认:选项卡:首选项:“总是在新选项卡中打开弹出窗口”
  • Chrome Default: Tab. Hidden preference:
  • Chrome默认值:选项卡。隐藏的偏好:
  • Firefox: Default: Tab https://support.mozilla.org/en-US/kb/tab-preferences-and-settings
  • Firefox:https://support.mozilla.org/en-US/kb/tab-preferences-and-settings默认值:选项卡
  • Safari: Default: Tab
  • Safari:默认选项卡

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

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

#14


-1  

Try with javascript function like this

尝试使用如下的javascript函数

Html:

Html:

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

Javascript:

Javascript:

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

#1


74  

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

我们不能做某些事是好事。target=_blank仍然被滥用,弹出窗口已经被执行到死亡。

#2


40  

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: 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上证实了这一点。

#3


8  

No, there isn't.

不,没有。

#4


5  

I hope this will help you

我希望这能对你有所帮助

window.open(url,'_newtab');

window.open(url,“_newtab”);

#5


1  

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.

浏览器处理新窗口和新标签的方式是在浏览器的选项中设置的,只能由用户修改。

#6


1  

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

我没有尝试,但我认为它在所有浏览器中都适用:

target="_parent"

目标= " _parent "

#7


1  

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

#8


1  

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-name属性创建新选项卡或新窗口时,才可以使用target-new属性。

#9


0  

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

你可以改变Safari打开新页面的方式在Safari >首选项>选项卡> '在选项卡中打开页面而不是windows' > '自动'

#10


0  

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

你可以将IE设置为在new选项卡中打开链接,只需进入设置菜单。

#11


0  

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.

在Internet Explorer中,单击工具-> Internet选项。点击常规选项卡->选项卡->设置。选择“当弹出时”->总是打开弹出在新的标签选项。单击OK。

#12


0  

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>

#13


0  

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".

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

  • IE9+ Default: Tab : Preference: "Always open pop-ups in a new tab"
  • IE9+默认:选项卡:首选项:“总是在新选项卡中打开弹出窗口”
  • Chrome Default: Tab. Hidden preference:
  • Chrome默认值:选项卡。隐藏的偏好:
  • Firefox: Default: Tab https://support.mozilla.org/en-US/kb/tab-preferences-and-settings
  • Firefox:https://support.mozilla.org/en-US/kb/tab-preferences-and-settings默认值:选项卡
  • Safari: Default: Tab
  • Safari:默认选项卡

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

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

#14


-1  

Try with javascript function like this

尝试使用如下的javascript函数

Html:

Html:

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

Javascript:

Javascript:

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