Open rich text links in a new tab - update

Hello,

I have some collection templates with rich text, and I would like to have all links opened in a new tab. So I read this topic.
But since, the code has changed. So I tried this in my Google Chrome console :
jQuery(document).ready(function() { $('*[data-rt-link-type="external"]').attr("target", "_blank"); });
And this works wonderfully.

So then I tried to include this code inside webflow (both in general custom code, and in an embed component), but without success :
<script> jQuery(document).ready(function() { $('*[data-rt-link-type="external"]').attr("target", "_blank"); }); </script>

Do you have an idea ?
Thanks


The website

Yes I know, but I think this is a pretty general question. Here is the link. if that can help you (and me :wink: )
Thanks !

You need to make sure that JQuery is loaded before your script tries to rely on its functions. With webflow it is automatically loaded before the </body> tag. So your script should loaded after JQuery. Meaning you need to have it placed in the template>settings>custom code> Before </body> tag - input field.

Give that a shot.
BTW: If you share your published site URL it is easy for someone to see the rendered issue and code. Can’t see that URL inside of a read only Shared Link.

1 Like

Ok, thanks for the tip. I tried this in this “custom code” section but maybe I did something wrong.
My published site URL is here.

Hey, thanks a bunch !! That works now !