和 有什么区别?如果我只想在新标签页/窗口中打开链接,应该使用哪个?" />
和 有什么区别?如果我只想在新标签页/窗口中打开链接,应该使用哪个?">
和 有什么区别?如果我只想在新标签页/窗口中打开链接,应该使用哪个?" />
What's the difference between
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
Security recommendation
As Daniel and Michael have pointed out in the comments, when using target
Using
Using
it will search for a tab or window with the context name "_new"
if a "_new" tab/window is found, then the URL is loaded into it
if it's not found, a new tab/window is created with the context name "_new", and the URL loaded into it
Note
Adding some confusion to this, in HTML4 the
TL;DR USE _blank
The target attribute specifies where to open the linked document.
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.
I know this is an old question and the correct answer, use
It is recommended (performance benefits) to use:
This may have been asked before but:
"every link that specifies target="_new" looks for and finds that window by name, and opens in it.
If you use target="_blank," a brand new window will be created each time, on top of the current window."
from here: http://thedesignspace.net/MT2archives/000316.html
it's my understanding that
Using one of the reserved target names will bypass the "looking" phase. So,
At least this is how I interpret the rules.
Caution - remember to always include the "quotes" - at least on Chrome,
The latter opens each link in a new tab/window. The former (missing quotes) opens the first link you click in one new tab/window, then overwrites that same tab/window with each subsequent link you click (that's named also with the missing quotes).
_blank as a target value will spawn a new window every time,
_new will only spawn one new window.
Also, every link clicked with a target value of _new will replace the page loaded in the previously spawned window.
You can click here When to use _blank or _new to try it out for yourself.
The target attribute of a link forces the browser to open the destination page in a new browser window. Using
In order to open a link in a new tab/window you'll use
value
value
target attribute with all its values on a element: video demo
The use of _New is useful when working on pages that are Iframed. Since target="_blank" doesn't do the trick and opens the page on the same iframe... target new is the best solution for Iframe Pages. Just my five cents.
Success story sharingtarget="_blank" vs. target="_new"
<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?
_new
doesn't have any special meaning. You could write _white_little_lamb
as well.
_new
" doesn't have any special meaning?
target="_blank"
without rel="noopener"
is a potential security vulnerability. Search for rel="noopener"
to learn more.
_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.
_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.
target="_blank"
will instruct the browser to create a new browser tab or window when the user clicks on the link.
target="_new"
is technically invalid according to the specifications, but as far as I know every browser will behave the same way:
target="_new"
will behave exactly the same as target="new"
, and the latter is valid HTML while the former is invalid HTML.
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.
target="_new"
, they both will open in the same tab, one overwriting the other?
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
_blank
, has been mentioned several times, but using <a target="somesite.com" target="_blank">Link</a>
is a security risk.
<a href="somesite.com" target="_blank" rel="noopener noreferrer">Link</a>
target="_blank"
opens a new tab in most browsers.
target = whatever
will look for a frame/window with that name. If not found, it will open up a new window with that name. If whatever == "_new"
, it will appear just as if you used _blank
except.....
target = "_blank"
on a dozen links will open up a dozen blank windows, but target = whatever
on a dozen links will only open up one window. target = "_new"
on a dozen links may give inconstant behavior. I haven't tried it on several browsers, but should only open up one window.
target=_blank
(no quotes) is NOT THE SAME as target="_blank"
(with quotes).
_new
as described?
_new
isn't a magical key word, it's just a name, if a window with that name exists it'll reuse it, otherwise it'll open it. Clicking multiple links for that window will just open different pages in the named window, rather than opening multiple new pages.
ignore
targets that starts with underline but are not keywords. There are no suggestions for what a browser should do when it "ignores" an invalid target name. Possibilities include: (1) treat it like "_blank" (2) treat it like a window name (as if there wasn't an illegal underscore) (3) treat it like a explicitly empty window name (4) treat it like there was no target attribute. -- Any browser could pick any of the interpretations.
_blank
as a target value will spawn a new window every time while using _new
will only spawn one new window and every link clicked with a target value of _new
will replace the page loaded in the previously spawned window
<a target="_blank">
.
_blank
= targeted browsing context: a new one: tab or window depending on your browsing settings
_new
= not valid; no such value in HTML5 for target attribute on a element
Follow WeChat
Want to stay one step ahead of the latest teleworks?
Subscribe Now
相似问题
valid browsing context name
or keyword is any string that is either avalid browsing context name
or ...."rel="noopener noreferrer"
due to javascript attack vulnerability oftarget="_blank"