How to open link in a new tab in HTML?
Open a link in a new tab in HTML by using the target
attribute with _blank
value in your <a>
tag, as shown below:
Replace URL
with your desired link and Link Text
with the visible, clickable text.
Fortifying links against tab-nabbing
For secure new tab opening, add rel="noopener noreferrer"
to your <a>
tags:
Our friendly HTML tag is now armored against potential tab-nabbing!
Default targets with <base>
tag
Use the <base>
tag in the <head>
section to set a default target
for all links:
Never forget: the <base>
tag has your base-line back!
Controlling link context
Be the maestro of your link's behavior with these target settings:
target="_self"
: Link opens in the same frame or window.target="_parent"
: Navigates out of an iframe or nested browsing context.target="_top"
: Escapes any and all frames. The linked document rules supreme.target="framename"
: Specifies where a link should open within a hierarchical structure.
Employing JavaScript when new tabs are blocked
If new tabs are blocked, beckon the powers of JavaScript with window.open
:
Trigger this function with an onclick
event.
Utilizing dynamic scripting for secure linkage
Add security enhancements to external links dynamically with some jQuery ninja magic:
Allory, the jQuery ninja, says: "All external links, be gone!" 🐱👤
Was this article helpful?