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.