本文翻译自:Open link in new tab or window [duplicate]
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? 是否可以在新标签页而不是同一标签页中打开a href
链接?
<a href="http://your_url_here.html">Link</a>
#1楼
参考:https://stackoom.com/question/13Fj9/在新标签页或窗口中打开链接-重复
#2楼
You should add the target="_blank"
and rel="noopener noreferrer"
in the anchor tag. 您应该在锚标记中添加target="_blank"
和rel="noopener noreferrer"
。
For example: 例如:
<a target="_blank" rel="noopener noreferrer" href="http://your_url_here.html">Link</a>
Adding rel="noopener noreferrer"
is not mandatory, but it's a recommended security measure. 添加rel="noopener noreferrer"
不是强制性的,但这是建议的安全措施。 More information can be found in the links below. 可以在下面的链接中找到更多信息。
Source: 资源:
- MDN | MDN | HTML element
<a>
| HTML元素<a>
| attributetarget
属性target
- About rel=noopener 关于rel = noopener
- Opens External Anchors Using rel="noopener" 使用rel =“ noopener”打开外部锚点
#3楼
set the target
attribute of your <a>
element to "_tab"
将<a>
元素的target
属性设置为"_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. EDIT2:根据我从评论中得出的结论。 setting target to _blank will take you to a new tab or window (depending on your browser settings). 将target设置为_blank会将您带到新的标签页或窗口(取决于您的浏览器设置)。 Typing anything except one of the ones below will create a new tab group (I'm not sure how these work): 键入以下内容之一以外的任何内容都会创建一个新的标签组(我不确定它们的工作方式):
_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楼
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. 有些像新窗户。
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 (eg middle click, Ctrl +click, or normal click). 使用_blank
将告诉浏览器使用新的选项卡/窗口,具体取决于用户的浏览器配置以及他们如何单击链接(例如,中键单击, Ctrl +单击或常规单击)。
#5楼
您可以通过设置target="_blank"
来简单地做到这一点,w3schools有一个示例 。