Developer forum

Forum » Swift » Open external links in new tab

Open external links in new tab

Suzi Louring
Suzi Louring
Reply

Hi

DW 10.7.3
Swift: 1.26.4

I can't get my external links in the footer to open in a new window.
I have read the docs here: https://doc.dynamicweb.dev/documentation/implementing/swift/other/swiftwebsitesettings.html?q=Open%20external%20links%20in%20new%20tab#master-settings

I have inserted some social links in the Navigation item and want them to open in a new window.

What am I missing?


/Suzi

 

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

How did you insert the link? If you have inserted them using the rich text editor, you need to set the target in the editor.

The setting you mention is targeting buttons etc. (all link editors) in regular content elements - not links in RTE.

BR Nicolai

 
Suzi Louring
Suzi Louring
Reply

No, not the rich text editor.
I'm using the Navigation item and the links are page shortcuts.
On each page I have selected "External link".


/Suzi

 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Suzi

Those links are not covered by that feature - none of the navigation templates is setting target.

A  simple workaround is to add this piece of JS to your customer header include file:

<script>
  document.addEventListener('DOMContentLoaded', () => {
    const links = document.querySelectorAll('a[href*="://"]')
    links.forEach(link => {
      link.setAttribute('target', '_blank')
    })
  })
</script>
 
Suzi Louring
Suzi Louring
Reply

Hi Nicolai

Thanks.

It would make sense if this type of link is covered by that feature. 
It's often used to put social links in the footer.
And maybe you should update the docs ;-)
"If checked, all external links on your website will open in a new tab or browser window when clicked"


/Suzi

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Suzi

I belive on of the documentations states that:

https://doc.dynamicweb.com/swift/setup-project/guides/open-external-links-in-a-new-tab

I can see the new one says something different. Will have it corrected.

Sorry about the confusion.

 

You must be logged in to post in the forum