<a target="_new">
和 <a target="_blank">
有什么区别?如果我只想在新标签页/窗口中打开链接,应该使用哪个?
最佳答案
使用“_blank”
根据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
也就是说HTML5中没有_new
这样的关键字,而not in HTML4 (and consequently XHTML) either .这意味着,如果您将其用作目标属性的值,则无论如何都不会出现一致的行为。
安全建议
正如 Daniel 和 Michael 在评论中指出的那样,当使用 target _blank
指向不受信任的网站时,您还应该设置 rel="noopener"
.这可以防止打开站点通过 JavaScript 与打开器混淆。见 this post了解更多信息。
关于html - 目标 ="_blank"与目标 ="_new",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4964130/