[英]Open link in new tab or window [duplicate]
是否可以在新选项卡而不是同一选项卡中打开a href
链接?
<a href="http://your_url_here.html">Link</a>
您应该在锚标记中添加target="_blank"
和rel="noopener noreferrer"
。
例如:
<a target="_blank" rel="noopener noreferrer" href="http://your_url_here.html">Link</a>
添加rel="noopener noreferrer"
不是强制性的,但它是推荐的安全措施。 更多信息可以在下面的链接中找到。
资源:
决定链接是在新选项卡还是新窗口中打开不应由您决定,因为最终该选择应由用户浏览器的设置来完成。 有些人喜欢标签; 有些喜欢新的窗户。
使用_blank
将告诉浏览器使用新的选项卡/窗口,这取决于用户的浏览器配置以及他们单击链接的方式(例如,中键单击、 Ctrl +单击或正常单击)。
此外,某些浏览器没有标签功能,因此无法在新标签中打开链接,只能在新窗口中打开。
将<a>
元素的target
属性设置为"_tab"
编辑:它有效,但是 W3Schools 说没有这样的目标属性: http ://www.w3schools.com/tags/att_a_target.asp
EDIT2:根据我从评论中得出的结论。 将 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
您可以通过设置target="_blank"
来简单地做到这一点,w3schools 有一个示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.