All links open in new window unless they live on my website: Brooklyn Theme

New Member
1 0 0

I have tried looking at the tutorials but have not found exactly what I need for Brooklyn Minimal theme. I want any links that are not on my website to open in a new tab or window. I don't care which just as long as it's not in the same window taking you out of my store! Yikes! 

 

Thank you!

0 Likes
Shopify Expert
665 170 199
Hi, Freebirdjess,
 
This is Evita from On The Map. 
 
You can try this code and let me know if this worked.
document.querySelectorAll('a').forEach(function(element) {
  element.addEventListener('click', function (e) {
    if (!e.target.href.includes('https://MY_STORE_URL.com')) {
      window.open(e.target.href,'_blank');
    }
  });
});
 
 
Best, 
Evita
On The Map Marketing | Developing custom Shopify Sites & Apps is our thing

- Install our latest app Accessibly - Makes your store accessible for everyone, helps to avoid fines
- Inc 5000 | Shopify Parners | 20+ stores launched | 300+ active clients
- Need help with your Shopify store? Reach out to us!
0 Likes