How to open link in a new tab in HTML?(如何在 HTML 的新选项卡中打开链接?)
问题描述
我正在处理一个 HTML 项目,但我不知道如何在没有 JavaScript 的情况下在新选项卡中打开链接.
I'm working on an HTML project, and I can't find out how to open a link in a new tab without JavaScript.
我已经知道 <a href="http://www.WEBSITE_NAME.com"></a>
在同一选项卡中打开链接.任何想法如何使它在一个新的打开?
I already know that <a href="http://www.WEBSITE_NAME.com"></a>
opens the link in the same tab. Any ideas how to make it open in a new one?
推荐答案
将链接的target
属性设置为_blank
:
<a href="#" target="_blank" rel="noopener noreferrer">Link</a>
有关其他示例,请参见此处:http://www.w3schools.com/tags/att_a_target.asp
For other examples, see here: http://www.w3schools.com/tags/att_a_target.asp
我之前建议使用 blank
而不是 _blank
,因为如果使用它,它会打开一个新选项卡,然后在再次单击链接时使用相同的选项卡.然而,这仅仅是因为,正如 GolezTrol 所指出的,它指的是框架/窗口的名称 a,当再次按下链接以在同一选项卡中打开它时,将设置和使用该名称.
I previously suggested blank
instead of _blank
because, if used, it'll open a new tab and then use the same tab if the link is clicked again. However, this is only because, as GolezTrol pointed out, it refers to the name a of a frame/window, which would be set and used when the link is pressed again to open it in the same tab.
rel="noopener noreferrer"
是为了防止新打开的标签页恶意修改原来的标签页.有关此漏洞的更多信息,请阅读以下文章:
The rel="noopener noreferrer"
is to prevent the newly opened tab from being able to modify the original tab maliciously. For more information about this vulnerability read the following articles:
- 目标=_blank"漏洞举例
- 使用 target='_blank 的外部链接'
这篇关于如何在 HTML 的新选项卡中打开链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 HTML 的新选项卡中打开链接?


基础教程推荐
- 我什么时候应该在导入时使用方括号 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 动态更新多个选择框 2022-01-01