Craft Theme - How to Open External Links In a New Tab

Craft Theme - How to Open External Links In a New Tab

TomMc
Excursionist
31 3 7

Hey guys,

 

We were using code to open external links in a new tab (using this tip https://ed.codes/blog/shopify-open-external-links-in-new-tab) up to Version 9; however, the code no longer works after subsequent updates. We are using the Craft theme. Does anyone have a solution that works for the latest version of Craft? We've tried fixes posted in here but, so far, none of them take.

 

Here is our store: 

https://anniemccormickdesigns.com/

 

Thanks,

Tom

 

 

Replies 2 (2)

Guleria
Shopify Partner
4113 804 1155

Hello @TomMc ,

 

There is no issue with the code you shared.

Maybe issue in your other changes which makes a conflict with this JS. I suggest reverting the changes you did recently or find the conflict manually to make it work.

 

Regards
Guleria 

 

- Custom themes, UI/UX design, ongoing maintenance & support.
- Drop an email   if you are looking for quick fix or any customization
- Email: guleriathakur43@gmail.com Skype: live:navrocks1
- Try GEMPAGES a great page builder

namphan
Shopify Partner
2689 349 398

Hi @TomMc,

Please change code:

<script>
      const links = document.links;
      for (let i = 0; i < links.length; i++) {
        if (links[i].hostname !== window.location.hostname) {
          links[i].target = '_blank';
          links[i].rel = 'noreferrer noopener';
        }
      }
</script>
Coffee tips fuels my dedication.
Shopify Development Service
PageFly Page Builder Optimize your Shopify store (Free plan available)
Need help with your store? namphan992@gmail.com