Jump to content

How to open summary image links in another tab?

Go to solution Solved by Beyondspace,

Recommended Posts

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

On the "Listen" section of my home page are twelve buttons (really hyperlinked  images) to various podcasting platforms. Spotify, Stitcher, etc.

For these "buttons" to wrap and scale properly, I must use a "summary" block set to "Grid." Problem is, clicking on the images now opens the link in your current tab, rather than creating a new one.

To solve this I found and deployed this code in the footer:

<script>
  document.querySelector('.sqs-block-summary-v2 a').setAttribute('target', '_blank');
</script>

So far I've succeeded in making the first image in the summary block open its link in a new tab, but every other image still opens the link in the current tab.

I'm guessing a minor change to the existing code will solve this, but I'm in over my head at this point. Help!

Link to comment
  • Solution
On 4/7/2021 at 1:43 AM, SpaceRants said:

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

On the "Listen" section of my home page are twelve buttons (really hyperlinked  images) to various podcasting platforms. Spotify, Stitcher, etc.

For these "buttons" to wrap and scale properly, I must use a "summary" block set to "Grid." Problem is, clicking on the images now opens the link in your current tab, rather than creating a new one.

To solve this I found and deployed this code in the footer:


<script>
  document.querySelector('.sqs-block-summary-v2 a').setAttribute('target', '_blank');
</script>

So far I've succeeded in making the first image in the summary block open its link in a new tab, but every other image still opens the link in the current tab.

I'm guessing a minor change to the existing code will solve this, but I'm in over my head at this point. Help!

You gotta select ALL items, modified code as follow

<script>
document.addEventListener('DOMContentLoaded', function() {
  var summary = document.querySelectorAll('.sqs-block-summary-v2 a');

summary.forEach(function(item) {
    item.setAttribute('target', '_blank');

});
});

</script>

Element.querySelectorAll() - Web APIs | MDN (mozilla.org)

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
  • 1 month later...
On 6/7/2021 at 9:53 PM, bluShiftAero said:

On a website with multiple galleries, how would you update the selector for just one gallery?

replace this class name

Quote

.sqs-block-summary-v2 a

with

Quote

#summary-block-id a

Find summary block id with this tool https://chrome.google.com/webstore/detail/squarespace-id-finder/igjamfnifnkmecjidfbdipieoaeghcff?hl=en

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • 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.