Jump to content

FORTE Template - How to open a clickthrough URL in a new tab

Recommended Posts

  • Replies 2
  • Views 780
  • Created
  • Last Reply
23 minutes ago, angelinapilarinos said:

Site URL: https://www.angelinapilarinos.com/

Hi I have several gallery pages that have clickthrough URLs connected to my smugmug account.  When you click on the image I want a new tab to open to my smugmug page.  At the moment it is not opening in a new tab.  Can someone tell me what code I need to use to make these links open in a new tab?  Thank you!

Kindly add this snippet to Settings->Advanced->Code Injection->Header

<script>
  document.addEventListener('DOMContentLoaded', function() {
        var slides = document.querySelectorAll(".slide [data-click-through-url]")
        for (var slides of slides) {
            slides.addEventListener('click', function(e) {
                var url = this.getAttribute("data-click-through-url");
                console.log(url);
                if (url) {
                    e.preventDefault();
                    e.stopPropagation();
                    window.open(url, '_blank');
                }

            })
        }
  });
</script>

 

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.