target=_blank vs. target=_new
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.
What is the difference between target=_blank and target=blank?
blank
targets an existing frame or window called "blank". A new window is created only if "blank" doesn't already exist.
_blank
is a reserved name which targets a new, unnamed window.
Open link in new tab in browser vs. target=_blank in HTML
target="_blank"
generally will open the link in where ever the browser's configuration specifies it should. To my knowledge there is no way to control how this works in the markup itself. Have you tried this in multiple browsers?
EDIT: to simulate the "open in new tab" functionality, target="_blank"
is correct.
Is it alright to use target=_blank in HTML5?
It looks like target="_blank"
is still alright. It is listed as a browsing context keyword in the latest HTML5 draft.
what is the difference between target value blank,self, parent,top in HTML?
From the specification:
_blank
The user agent should load the designated document in a new, unnamed
window._self
The user agent should load the document in the same frame as the
element that refers to this target._parent
The user agent should load the document into the immediate FRAMESET
parent of the current frame. This value is equivalent to _self if the
current frame has no parent._top
The user agent should load the document into the full, original window
(thus canceling all other frames). This value is equivalent to _self
if the current frame has no parent.
http://www.w3.org/TR/html4/types.html#type-frame-target
Link with target=_blank and rel=noopener noreferrer still vulnerable?
You may be misunderstanding the vulnerability. You can read more about it here: https://www.jitbit.com/alexblog/256-targetblank---the-most-underestimated-vulnerability-ever/
Essentially, adding rel="noopener noreferrer"
to links protects your site's users against having the site you've linked to potentially hijacking the browser (via rogue JS).
You're asking about removing that attribute via Developer Tools - that would only potentially expose you (the person tampering with the attribute) to the vulnerability.
Update as of 2021: All current versions of major browsers now automatically use the behavior of rel="noopener"
for any target="_blank"
link, nullifying this issue. See more at chromestatus.com.
Difference between _self, _top, and _parent in the anchor tag target attribute
While these answers are good, IMHO I don't think they fully address the question.
The target attribute in an anchor tag tells the browser the target of the destination of the anchor. They were initially created in order to manipulate and direct anchors to the frame system of document. This was well before CSS came to the aid of HTML developers.
While target="_self"
is default by browser and the most common target is target="_blank"
which opens the anchor in a new window(which has been redirected to tabs by browser settings usually). The "_parent"
, "_top"
and framename
tags are left a mystery to those that aren't familiar with the days of iframe site building as the trend.
target="_self"
This opens an anchor in the same frame. What is confusing is that because we generally don't write in frames anymore (and the frame
and frameset
tags are obsolete in HTML5) people assume this a same window function. Instead if this anchor was nested in frames it would open in a sandbox mode of sorts, meaning only in that frame.
target="_parent"
Will open the in the next level up of a frame if they were nested to inside one another
target="_top"
This breaks outside of all the frames it is nested in and opens the link as top document in the browser window.
target="framename
This was originally deprecated but brought back in HTML5. This will target the exact frame in question. While the name
was the proper method that method has been replaced with using the id
identifying tag.
<!--Example:-->
<html>
<head>
</head>
<body>
<iframe src="url1" name="A"><p> This my first iframe</p></iframe>
<iframe src="url2" name="B"><p> This my second iframe</p></iframe>
<iframe src="url3" name="C"><p> This my third iframe</p></iframe>
<a href="url4" target="B"></a>
</body>
</html>
What's the meaning of adding a target=_blank attribute in a div?
<div>
doesn't have target
attribute
You can use target="_blank"
in <a>
, for example
The
target
attribute specifies where to open the linked document.The
target
attribute can have one of the following values:
_blank
- Opens the linked document in a new window or tab_self
- Opens the linked document in the same window/tab 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 windowframename
- Opens the linked document in a named frame which was opened with JavaScript
source: W3Schools - HTML Links
Related Topics
How to Vertically Align Text Inside a Flexbox
≪!--[If !Ie]≫ Is Not Working as Expected in This Case
Html Table Headers Always Visible At Top of Window When Viewing a Large Table
Css-Only Scrollable Table With Fixed Headers
Why Is It a Bad Thing to Have Multiple HTML Elements With the Same Id Attribute
Difference Between Id and Class in Css, and When Should I Use Them
Change Select List Option Background Colour on Hover
How to Create Download Link in Html
Align an Element to Bottom With Flexbox
Why Does Styling the Background of the Body Element Affect the Entire Screen
Show an Image Preview Before Upload
Ie8 Support For CSS Media Query
How to "Disable" Zoom on a Mobile Web Page
Html/Css Triangle With Pseudo Elements
Why Do Absolute Elements Stack Up on Each Other Instead of Stacking One After the Other
Trouble With Parsing Table Data in Perl
Using Flex Order Property to Re-Arrange Items For Desktop and Mobile Views