Add

Lorem ipsum

Lorem ipsum

A
A
A
No-code

0 views

2 min

How to Open External Links in a New Tab in Webflow

Learn how to automatically open all external links in a new tab in Webflow with JavaScript.

In this tutorial, Sandro, cofounder of Gemeos Webflow agency, shows you how to automatically open all external links in a new tab on your Webflow site.

Example

Click "Apply script" to see the external links updated

ApproachAdvantageDrawback
JS script (this tutorial)Automatic, zero maintenanceRequires JavaScript to be enabled
Manual target='_blank' attributeSimpleTedious with lots of links
Webflow custom attributePer linkNot automatic

The script

This script automatically detects all links that point to a different domain than yours and adds target="_blank" and rel="noopener noreferrer" to them.

document.querySelectorAll('a[href]').forEach(function(link) {
if (link.hostname !== window.location.hostname && link.hostname !== '') {
link.setAttribute('target', '_blank');
link.setAttribute('rel', 'noopener noreferrer');
}
});

Desktop only version

On mobile, opening in a new tab is less useful (multi-tab browsing feels less natural). To apply the script only on desktop:

if (window.innerWidth >= 768) {
document.querySelectorAll('a[href]').forEach(function(link) {
if (link.hostname !== window.location.hostname && link.hostname !== '') {
link.setAttribute('target', '_blank');
link.setAttribute('rel', 'noopener noreferrer');
}
});
}

good to know

The rel='noopener noreferrer' attribute is essential on all target='_blank' links. Without it, the opened page can access window.opener and potentially modify the original page (tabnapping attack). Webflow has added rel='noopener' automatically since 2021, but check your source code to make sure it's applied.

Conclusion

This script is added once globally and automatically applies to all links on the site.

Good to know

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Lorem ipsum dolor sit amet consectetur.

Lorem ipsum dolor sit amet consectetur. Aliquam orci sagittis dignissim sapien praesent donec.

Lorem ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Published on

You might be interested in these tutorials

Similar tutorials

SEO / GEO

5 min read

5 views

How to Set Up a Redirect in Webflow? (2026)

Updated on 19.12.2025 by Sandro DA SILVA

SEO / GEO

5 min read

5 views

Add structured data to your Webflow site?

Updated on 21.08.2025 by Sandro DA SILVA

No-code

5 min read

5 views

How to Obfuscate a Link in Webflow

Updated on 23.04.2025 by Sandro DA SILVA

Let’s f*****G GO !!

Ready to launch
Your business?

Alexandre

Max

Enora

Bryan

Cannelle

Tiphaine

You'll :heart: our collaboration...