Target="_blank" vs. target="_new"
I strongly recommend opting for target="_blank"
for opening links in a new tab consistently across all browsers. target="_new"
is not a recognized standard and may result in unexpected tab reuse. Here's an example:
In essence, stick with target="_blank"
when opening links externally and dodge the non-standard and erratic target="_new"
. For improved security and performance, consider using rel=noopener
and rel=noreferrer
.
Secure & Optimize: How "noopener" & "noreferrer" come to the rescue
When using target="_blank"
, security and performance are key. The additional attribute rel="noopener"
is your bodyguard, preventing the newly opened page from gaining access to your page via the window.opener
JavaScript object and curbing potential JavaScript antics.
Also, welcome the rel="noreferrer"
as an extra layer of defence. Along with user privacy, it facilitates a nippier page load speed by avoiding the HTTP Referer header in the request.
Here's your shielded approach:
In a nutshell, understanding and applying these attributes shields against security vulnerabilities in all scenarios where user-generated content leads to external links.
Naming Game: Understanding the browser's behavior with named targets
The reserved target names have a special place in HTML, and "_blank"
is one of them. When you use target="SomeWindowName"
, the browser turns into a detective, looking for a window or tab named "SomeWindowName", and reuses it if it exists, else, it creates one.
With "_new"
, most browsers consider it as a named window target:
This can cause erratic behaviour since "_new"
is not recognized as a special name like "_blank", "_self", "_parent", "_top". The solution? Avoid target="_new"
to assure predictability and user-friendly navigation.
The Holy Book: Reserved target names and HTML standards
The HTML specification defines reserved target names like "_blank"
, used for their special capabilities to offer consistency across browers. The browsers bible has explanations for the uses:
"_blank"
: A new window or tab would be opened as fresh as a daisy on each click."_self"
: Opens in the same frame or window. Feels like home."_parent"
: The parent frame is targetted, but not that parent talk again!"_top"
: Opens in the full body of the window. A.K.A, the boss level!
Refer to the HTML5 Specification and W3C recommendations for the detailed commandments on these attributes.
Following the legends - Insights from experts on "rel" attributes
Expert insights have always been valuable, and Mathias Bynens and Jake Archibald are the top guns here. Their crystal clear explanation of "rel"
attributes are guidebooks every web developer should have on their shelf. Their expertise helps you navigate the choppy waters of security implications and best practices.
Was this article helpful?