如何在HTML的新标签页中打开链接? [英] How to open link in a new tab in 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:
这篇关于如何在HTML的新标签页中打开链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!