如何在 HTML 的新标签页中打开链接? [英] How to open link in a new tab in HTML?

查看:44
本文介绍了如何在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆