How can I make all external links open in a new tab by default on my Webflow site, while keeping internal links opening in the current tab? Is there a solution that doesn't involve manually ticking a box for each link? Thank you!

TL;DR
  • Go to Project Settings in Webflow and add the custom jQuery script in the Footer Code section to open external links in a new tab.
  • Test the functionality by publishing the site to ensure external links open in a new tab while internal links remain unaffected.

You want to ensure that all external links open in a new tab automatically, while internal links remain unaffected on your Webflow site.

1. Use Custom Code in Webflow

  • Open your Webflow project and go to the Project Settings.
  • Navigate to the Custom Code section.
  • In the Footer Code section, you can insert jQuery to achieve this functionality since Webflow automatically includes jQuery.

2. Add jQuery Code

  • Paste the following jQuery script, which will open external links in a new tab:
  • Before copying the code: Ensure jQuery is enabled or included. If not, this won't work.

  

$(document).ready(function() {
  $('a').each(function() {
    var a = new RegExp('/' + window.location.host + '/');
    if (!a.test(this.href)) {
      $(this).attr('target', '_blank');
    }
  });
});

3. Publish and Test

  • Publish your site to apply the changes.
  • Test by visiting the site and checking that all external links now open in a new tab, while internal links do not.

Summary

By inserting a jQuery snippet into the Custom Code settings of your Webflow project, you can automate the process of opening external links in a new tab. This approach saves you from manually setting each link individually.

Rate this answer

Other Webflow Questions