USAGE: target="xyz" [don't forget double quotes]
_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
SINCE "_new" is not any of these IT WILL COME UNDER "framename" so if a user re-clicks on that hyperlink it will not open a new tab instead update the existing tab. Whereas in _blank if user clicks twice then 2 new tabs open.
12 回答
在处理Iframed的页面时,使用_New非常有用 . 由于target =“_ blank”不起作用并在同一iframe上打开页面... target new是iframe Pages的最佳解决方案 . 只是我的五美分 .
使用“_blank”
根据HTML5 Spec:
这意味着在HTML5和not in HTML4 (and consequently XHTML) either中没有
_new
这样的关键字 . 这意味着,如果将此值用作目标属性的值,则不会出现任何一致的行为 .安全建议
正如丹尼尔和迈克尔在评论中指出的,当使用指向不受信任的网站的目标
_blank
时,你应该另外设置rel="noopener"
. 这可以防止开放网站通过JavaScript搞乱开场白 . 有关更多信息,请参见this post .使用
target="_blank"
将指示浏览器在用户单击链接时创建新的浏览器选项卡或窗口 .根据规范,使用
target="_new"
在技术上是无效的,但据我所知,每个浏览器的行为方式都相同:它将搜索上下文名称为"_new"的选项卡或窗口
如果找到"_new"选项卡/窗口,则会将URL加载到其中
如果找不到,则创建一个新的选项卡/窗口,其上下文名称为"_new",并且URL已加载到其中
注意
target="_new"
的行为与target="new"
完全相同,后者是有效的HTML而前者是无效的HTML .为此添加一些混淆,在HTML4中,不推荐使用
target
属性 . 在HTML5中,这个决定被颠倒了,它再次成为规范的官方部分 . 无论您使用的是哪种版本的HTML,所有浏览器都支持target
,但如果您的doctype是HTML4,则某些验证程序会将使用标记为已弃用 .TL; DR
USE _blank
target属性指定打开链接文档的位置 .
SINCE "_new" is not any of these IT WILL COME UNDER "framename" so if a user re-clicks on that hyperlink it will not open a new tab instead update the existing tab. Whereas in _blank if user clicks twice then 2 new tabs open.
这可能是之前被问过但是:
“指定target =”_ new“的每个链接都会查找并按名称查找该窗口,并在其中打开 .
如果你使用target =“_ blank”,那么每次都会在当前窗口的顶部创建一个全新的窗口 . “
从这里:http://thedesignspace.net/MT2archives/000316.html
我知道这是一个老问题和正确的答案,使用
_blank
,已多次提及,但使用<a target="somesite.com" target=_blank>Link</a>
is a security risk .recommended(performance benefits)使用
<a href="somesite.com" target="_blank" rel="noopener noreferrer">Link</a>
我的理解是
target = whatever
将寻找具有该名称的框架/窗口 . 如果没有找到,它将打开一个具有该名称的新窗口 . 如果是whatever == "_new"
,它就会像你使用_blank
一样出现.....使用其中一个保留的目标名称将绕过"looking"阶段 . 所以,
target = "_blank"
上的十几个链接会打开十几个空白窗口,但是十几个链接上的target = whatever
只会打开一个窗口 .target = "_new"
十几个链接可能会给出不一样的行为 . 我没有在几个浏览器上试过它,但应该只打开一个窗口 .至少这是我解释规则的方式 .
target="_blank"
在大多数浏览器中打开一个新选项卡 .注意 - 请记住始终包含"quotes" - 至少在Chrome上,
target=_blank
(没有引号)与target="_blank"
(带引号)不相同 .后者在新的选项卡/窗口中打开每个链接 . 前者(缺少引号)打开您在一个新选项卡/窗口中单击的第一个链接,然后使用您单击的每个后续链接(也使用缺少的引号命名)覆盖相同的选项卡/窗口 .
_blank作为目标值每次都会产生一个新窗口,
_new只会产生一个新窗口 .
此外,使用_new目标值单击的每个链接都将替换先前生成的窗口中加载的页面 .
你可以点击这里When to use _blank or _new自己尝试一下 .
链接的目标属性强制浏览器在新的浏览器窗口中打开目标页面 . 使用
_blank
作为目标值将每次生成一个新窗口,而使用_new
只会生成一个新窗口,并且每个链接目标值为_new
的链接将替换先前生成的窗口中加载的页面要在新标签/窗口中打开链接,您将使用
<a target="_blank">
.值
_blank
=目标浏览上下文:新的:选项卡或窗口,具体取决于您的浏览设置值
_new
=无效;在HTML5中没有元素的目标属性的值目标属性及其在元素上的所有值:video demo