All things Shopify and commerce
Hi There ,
I have recently added this code to open links in the site to open in new tab and it is working in desktop but when I click in the recommended products or recently viewed products in after clicking any specific products it is not opening in new tab , Any idea on how to solve this issue .
Site URL :: https://6v2hzrj6oxibj021-71493648693.shopifypreview.com
if (window.innerWidth > 768) {
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';
}
}
}
Hi @Anonymous Can you please provide me collaborated access so I can help you batter.
The code you have provided is a JavaScript snippet that opens links in a new tab on desktop devices only. The snippet works by first checking if the width of the window is greater than 768 pixels. If it is, then the snippet loops through all of the links on the page and adds the target="_blank" attribute to them. The target="_blank" attribute tells the browser to open the link in a new tab.
The snippet also adds the rel="noreferrer noopener" attribute to the links. This attribute tells the browser to prevent the website from tracking the user when they click on the link.
Here is a breakdown of the code:
if (window.innerWidth > 768) {
This line of code checks if the width of the window is greater than 768 pixels. If it is, then the snippet will execute the code inside the curly braces.
for (let i = 0, linksLength = links.length; i < linksLength; i++) {
This line of code loops through all of the links on the page. The variable i is used to keep track of the current link. The variable linksLength is the total number of links on the page.
if (links[i].hostname === window.location.hostname) {
This line of code checks if the hostname of the link is the same as the hostname of the current page. If it is, then the snippet will add the target="_blank" and rel="noreferrer noopener" attributes to the link.
links[i].target = '_blank'; links[i].rel = 'noreferrer noopener';
These lines of code add the target="_blank" and rel="noreferrer noopener" attributes to the link.
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024