本文翻译自:How to open link in new tab on html?
I'm working on an HTML project, and I can't find out how to open a link in a new tab without javascript. 我正在处理一个HTML项目,但是我不知道如何在没有JavaScript的情况下在新标签页中打开链接。
I already know that <a href="http://www.WEBSITE_NAME.com"></a>
opens the link in same tab. 我已经知道<a href="http://www.WEBSITE_NAME.com"></a>
在同一标签中打开了链接。 Any ideas how to make it open in a new one? 有什么想法如何使其在新的环境中打开吗?
#1楼
参考:https://stackoom.com/question/1CJTe/如何在HTML的新标签页中打开链接
#2楼
Set the 'target' attribute of the link to _blank
: 将链接的'target'属性设置为_blank
:
<a href="#" target="_blank" rel="noopener noreferrer">Link</a>
Edit: for other examples, see here: http://www.w3schools.com/tags/att_a_target.asp 编辑:有关其他示例,请参见此处: http : //www.w3schools.com/tags/att_a_target.asp
(Note: 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). (注意:我以前建议使用blank
而不是_blank
因为如果使用它,它将打开一个新选项卡,如果再次单击该链接,则将使用相同的选项卡。但是,这仅是因为正如GolezTrol所指出的那样,框架/窗口的名称a,当再次按下链接以在同一选项卡中将其打开时,将设置并使用该名称。
Security Consideration! 安全考虑!
The rel="noopener noreferrer"
is to prevent the newly opened tab from being able to modify the original tab maliciously. rel="noopener noreferrer"
可以防止新打开的选项卡能够恶意修改原始选项卡。 For more information about this vulnerability see these resources: 有关此漏洞的更多信息,请参见以下资源:
- https://dev.to/ben/the-targetblank-vulnerability-by-example https://dev.to/ben/the-targetblank-vulnerability-by-example
- https://support.detectify.com/customer/portal/articles/2792257-external-links-using-target-_blank- https://support.detectify.com/customer/portal/articles/2792257-external-links-using-target-_blank-
#3楼
target='_blank'
如果您未使用XHTML)。
#4楼
使用target="_blank"
:
<a href="http://www.example.com/" target="_blank" rel="noopener noreferrer">This will open in a new window!</a>
#5楼
Use the "target" attribute of the a tag and assign it to _blank. 使用标签的“目标”属性,并将其分配给_blank。 That is: 那是:
<a href="http://www.google.com" target="_blank" >Google in a New Tab or Window depending on the browser's capabilities</a>
#6楼
target =“ _ blank”总是为每次点击打开一个新标签,而target =“ tabName”会为每个点击打开一个新标签。