I want to Open Internal Links (Any links in front page) in a New Tab using Narrative theme

Solved
New Member
3 0 0

I had embedded a Spotify Player on my front page. If the customer is playing music on my front page ..the moment the customer clicks on a link in my front page, I would like those pages open in a new tab...not in the current tab itself..because the music he/she is listening to is getting interrupted ...

 

I've already changed the code to open "external links" in a new tab. But I just don't know how to change the "internal links" on my front page. Please help me with a solution!!!!

Here's a link to my website: findme-records.com

0 Likes
Highlighted

This is an accepted solution.

Hi there. If you want to open your link into new tab. I can give you a guideline for this.

var links = document.links;
for (let i = 0, linksLength = links.length ; i < linksLength ; i++) {
if (links[i].hostname !== window.location.hostname) {
links[i].target = '_blank'; links[i].rel = 'noreferrer noopener';
} }

CRO Expert at PageFly - Advanced Shopify Page Builder.
- PageFly Page Builder: Website | Facebook | LinkedIn | Group | Youtube
- [Tutorial] Get
more tips on using PageFly to soar sales this season
- [Master Guides]: Get Your Shopify Store Ready for Black Friday
0 Likes
Highlighted
New Member
3 0 0

Hi Richard,

Thanks for your help. It works on External links but not the internal links on my theme. Is there any way?

0 Likes
Highlighted

This is an accepted solution.

To make it work with internal links only replace:

 

if (links[i].hostname !== window.location.hostname) {

With:

if (links[i].hostname === window.location.hostname) {

Note that  !== has be replaced with ===

 

To make it work with internal and external links use:

 

var links = document.links;
for (let i = 0, linksLength = links.length ; i < linksLength ; i++) {
  links[i].target = '_blank';
  links[i].rel = 'noreferrer noopener';  
}
ScreenStaring
Software Development & Consulting
1 Like
Highlighted
New Member
3 0 0

Thank you so much! It works!

0 Likes