在新的标签或窗口中打开链接[复制]

时间:2022-09-22 18:43:52

This question already has an answer here:

这个问题已经有了答案:

Is it possible to open an a href link in a new tab instead of the same tab?

是否可以在新选项卡中打开一个href链接,而不是相同的选项卡?

<a href="http://your_url_here.html">Link</a>

4 个解决方案

#1


1461  

You should add the target attribute in the anchor tag with the value _blank.

您应该在锚标记中添加具有值_blank的目标属性。

For example:

例如:

<a target="_blank" href="http://your_url_here.html">Link</a>

Source: MDN | HTML element <a> | attribute target

来源:MDN | HTML元素 |属性目标

#2


203  

It shouldn't be your call to decide whether the link should open in a new tab or a new window, since ultimately this choice should be done by the settings of the user's browser. Some people like tabs; some like new windows.

不应该由您来决定链接应该在新选项卡中打开还是在新窗口中打开,因为最终这个选择应该由用户浏览器的设置完成。有些人喜欢标签;有些人喜欢新的windows。

Using _blank will tell the browser to use a new tab/window, depending on the user's browser configuration and how they click on the link (e.g. middle click, Ctrl+click, or normal click).

使用_blank将告诉浏览器使用一个新的选项卡/窗口,这取决于用户的浏览器配置以及他们如何点击链接(例如中间单击、Ctrl+单击或普通单击)。

#3


38  

set the target attribute of your <a> element to "_tab"

元素的目标属性设置为“_tab”

EDIT: It works, however W3Schools says there is no such target attribute: http://www.w3schools.com/tags/att_a_target.asp

编辑:它是有效的,但是W3Schools说没有这样的目标属性:http://www.w3schools.com/tags/att_a_target.asp。

EDIT2: From what I've figured out from the comments. setting target to _blank will take you to a new tab or window (depending on your browser settings). Typing anything except one of the ones below will create a new tab group (I'm not sure how these work):

根据我从评论中得出的结论。将target设置为_blank将带您到一个新的选项卡或窗口(取决于您的浏览器设置)。输入任何东西,除了下面的一个将创建一个新的标签组(我不确定这些是如何工作的):

_blank  Opens the linked document in a new window or tab
_self   Opens the linked document in the same frame as it was clicked (this is default)
_parent Opens the linked document in the parent frame
_top    Opens the linked document in the full body of the window
framename   Opens the linked document in a named frame

#4


24  

You can simply do that by setting target="_blank", w3schools has an example.

可以通过设置target="_blank"来实现,w3schools网站就是一个例子。

#1


1461  

You should add the target attribute in the anchor tag with the value _blank.

您应该在锚标记中添加具有值_blank的目标属性。

For example:

例如:

<a target="_blank" href="http://your_url_here.html">Link</a>

Source: MDN | HTML element <a> | attribute target

来源:MDN | HTML元素 |属性目标

#2


203  

It shouldn't be your call to decide whether the link should open in a new tab or a new window, since ultimately this choice should be done by the settings of the user's browser. Some people like tabs; some like new windows.

不应该由您来决定链接应该在新选项卡中打开还是在新窗口中打开,因为最终这个选择应该由用户浏览器的设置完成。有些人喜欢标签;有些人喜欢新的windows。

Using _blank will tell the browser to use a new tab/window, depending on the user's browser configuration and how they click on the link (e.g. middle click, Ctrl+click, or normal click).

使用_blank将告诉浏览器使用一个新的选项卡/窗口,这取决于用户的浏览器配置以及他们如何点击链接(例如中间单击、Ctrl+单击或普通单击)。

#3


38  

set the target attribute of your <a> element to "_tab"

元素的目标属性设置为“_tab”

EDIT: It works, however W3Schools says there is no such target attribute: http://www.w3schools.com/tags/att_a_target.asp

编辑:它是有效的,但是W3Schools说没有这样的目标属性:http://www.w3schools.com/tags/att_a_target.asp。

EDIT2: From what I've figured out from the comments. setting target to _blank will take you to a new tab or window (depending on your browser settings). Typing anything except one of the ones below will create a new tab group (I'm not sure how these work):

根据我从评论中得出的结论。将target设置为_blank将带您到一个新的选项卡或窗口(取决于您的浏览器设置)。输入任何东西,除了下面的一个将创建一个新的标签组(我不确定这些是如何工作的):

_blank  Opens the linked document in a new window or tab
_self   Opens the linked document in the same frame as it was clicked (this is default)
_parent Opens the linked document in the parent frame
_top    Opens the linked document in the full body of the window
framename   Opens the linked document in a named frame

#4


24  

You can simply do that by setting target="_blank", w3schools has an example.

可以通过设置target="_blank"来实现,w3schools网站就是一个例子。