Custom code to open all links in rich text in new tab

Hello,

I need to set all links within a rich text field to open in a new tab by default. The rich text field will probably have a style attached to it, if that matters. The reason is that I have rich text fields with dozens and sometimes hundreds of links and it’s not feasible to go through the multiple little clicks needed to set “open in new tab” for each one individually (this is a UI problem in Webflow imo).

My understanding is this is done using custom code. I have tried both of the following and neither work. Can someone help?


Here is my site Read-Only: https://preview.webflow.com/preview/surrogacyvoices?utm_medium=preview_link&utm_source=designer&utm_content=surrogacyvoices&preview=5659e76305825b10bd00c1240f6fb8a6&workflow=preview

1 Like

Hello! The second link you posted worked for me. I just pasted the code into my Project Settings > Custom Code section inside the Footer Code.

The script below is the one that worked for me:

jQuery(document).ready(function() {
 	$('*[data-rt-link-type="external"]').attr("target", "_blank");
  $( "a" ).attr("target", "_blank");
});

Hope this works for you!

Edit: So this works - for me - on Chrome, Firefox, and Edge, but NOT on Safari. I don’t know the answer to that… looks like this won’t work for me either.

2 Likes

Do you know where I do this within the project? I can’t find where to add code to the Footer

Open up your page settings (if you want it at the page level) or project settings (to add it globally for your site).

You’ll find text areas that allow you to copy / paste the Javascript mentioned.