blank" vs. target="
<a target="_new">
和<a target="_blank">
如果我只想在新的标签页/窗口中打开链接,应该使用哪一种?
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.
Using target="_blank"
will instruct the browser to create a new browser tab or window when the user clicks on the link.
Using target="_new"
is technically invalid according to the specifications, but as far as I know every browser will behave the same way:
Note target="_new"
will behave exactly the same as target="new"
, and the latter is valid HTML while the former is invalid HTML.
Adding some confusion to this, in HTML4 the target
attribute was deprecated. In HTML5 this decision was reversed, and it is an official part of the spec once again. All browsers support target
no matter what version of HTML you are using, but some validators will flag the use as deprecated if your doctype is HTML4.
TL;DR
USE _blank
The target attribute specifies where to open the linked document.
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.
链接地址: http://www.djcxy.com/p/20166.html上一篇: 在新选项卡或窗口中打开链接
下一篇: 空白“与目标=”