目标= QUOT; _blank" vs target =“_new” [英] target="_blank" vs. target="_new"

查看:363
本文介绍了目标= QUOT; _blank" vs target =“_new”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< a target =_ new> 和< a target =_ blank> ,如果我只想在新标签页/窗口中打开链接,应该使用哪一个? 使用 _blank

根据 HTML5规范
$ b


有效的浏览上下文名称是任何至少包含一个字符的字符串,不以U + 005F LOW LINE字符开头。 (以下划线开头的名字是为特殊关键字保留的。)



有效的浏览上下文名称或关键字是任何有效的字符串浏览上下文名称,或者这是对_blank,_self,_parent或_top之一的ASCII区分大小写匹配。 - Source


这意味着没有<$ c这样的关键字HTML5中的$ c> _new ,以及而不是在HTML4(也就是XHTML)中,也就是说,如果你使用这个值作为目标属性的值,将不会有任何一致的行为。



< h3>安全建议

正如Daniel和Michael在评论中指出的那样,当使用target _blank 指向一个不可信网站,您应该另外设置 rel =no开瓶器。这可以防止开放网站通过JavaScript混淆opener。有关详情,请参阅此文章


What's the difference between <a target="_new"> and <a target="_blank"> and which should I use if I just want to open a link in a new tab/window?

解决方案

Use "_blank"

According to the HTML5 Spec:

A valid browsing context name is any string with at least one character that does not start with a U+005F LOW LINE character. (Names starting with an underscore are reserved for special keywords.)

A valid browsing context name or keyword is any string that is either a valid browsing context name or that is an ASCII case-insensitive match for one of: _blank, _self, _parent, or _top." - Source

That means that there is no such keyword as _new in HTML5, and not in HTML4 (and consequently XHTML) either. That means, that there will be no consistent behavior whatsoever if you use this as a value for the target attribute.

Security recommendation

As Daniel and Michael have pointed out in the comments, when using target _blank pointing to an untrusted website, you should, in addition, set rel="noopener". This prevents the opening site to mess with the opener via JavaScript. See this post for more information.

这篇关于目标= QUOT; _blank&QUOT; vs target =“_new”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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