Streaming live at 10am (PST)

Code to open link in same window via CMS


#1

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


#2

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?


#3

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 .


#4

Do you have a designer share link and published link?


#5

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


#6

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>

#7

Thank you! This works.


#8

You’re welcome. Have a great week