Code to open link in same window via CMS

Hi, when I add a link to an external url to an image in a rich text field via the CMS, that link opens in a separate window. I have been told it might be possible to use some code so that the link opens in the same window. However, after much searching I still can’t figure out anything that works.

Any help would be hugely appreciated!

Thanks

If you add an external link in a CMS, or anywhere else in the site, and you test this link while still in the Designer’s Preview, the link will always open outside, in a new tab, because Webflow prevents you to close the Designer while working. But if you go test that link on the published site, it should open in the same tab.

There is actually a way to set a CMS RT link to open in another tab. And maybe it’s activated on your link. Select your link in edit mode, click on the gear icon, and you get this option:

download

Does this help?

Hi Vincent,

Thanks very much for your suggestions. Unfortunately it still opens in a new page even on the published site.

The gear icon only seems to be available for linking text but not for an image as far as I can see .

Do you have a designer share link and published link?

I do indeed - https://preview.webflow.com/preview/beaufort-12?preview=25ef7d878eea2c7be62ed2dc9b0e0747

This is the page I am testing on - trying to add the link to the image of a mac screen http://beaufort-12.webflow.io/administration/devon-feeney

Wow, I didn’t know linking an image in a CMS Rich Text field forces it to open in a new window.

Seems like there is no way in the UI to override this behavior, so you’re going to have to use some custom code here.

Put this in the Page Footer of the Template page:

<script>
Webflow.push(function() {
  $('[data-rt-link-type]').removeAttr('target');
});
</script>

Thank you! This works.

You’re welcome. Have a great week

fantastic : for cms template
add it to before body as there is no footer for cms template pages
I have been searching for this for weeks!

Is this code still working? I pasted it in the [before tag] of my cms collection page, but it still isn’t working. Is there a new code?