Jump to content

Gallery: External link in new window/tab?

Recommended Posts

  • Replies 38
  • Views 41.3k
  • Created
  • Last Reply
  • 3 weeks later...
  • 1 month later...
  • 4 months later...

I'm having a related issue using a link to a PDF in the Gallery page.

I have added the code above, as suggested, to the end of the pdf title. But the added code doesn't seem to make a difference -- the PDF just opens in the same tab of the web browser, just as before.

The PDF file with added code is:

BreathebyDavidLobenstineSpreads.pdf"target="blank

What am I doing wrong?

(And if you want to see the webpage itself: https://fullbreathmassage.com/writings)

Thanks much for your help!

David

Link to comment
  • 2 months later...

Thank you for explaining this! Now I get a slight idea of what I'm doing :) It works like charm for most links.

BUT NOT for the ones that end with / (slash). The code that I add after / seems to be treated as part of the address and not as code. It still takes me to the target website but I end up with the Page Not Found message.

https://sitename.com/some-blog/article-about-something"target="_blank - OK

https://sitename.com/some-blog/article-about-something/"target="_blank - NOT OK :(

I tried deleting / and then adding "target="_blank => Page Not Found

Please help!

www.afterworkdiy.ru

Link to comment
  • 2 weeks later...
  • 4 months later...
  • 2 weeks later...
  • 1 year later...

I am using Five template, have a Gallery Summary Block placed on homepage that was not allowing links (video, pdfs) to open in a new browser window.

After much searching, reading, trial and error, I think I finally pieced together a method to make all of the links in a gallery summary block open in a new browser window (without affecting the rest of the links on the site page).

First, enable jQuery on your site by going to main menu (Settings/Advanced/Code Injection) and pasting this code snippet into the header field:


<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>

Next, go to the page you want your gallery summary block to allow external links to happen on, and go to (Settings/Advanced/Page Header Code Injection) and paste this code snippet in the box:


<script>
$(document).ready(function() {
   $('.sqs-gallery-container a').click(function(event) {
       event.preventDefault(); // preventDefault first
       var link = $(this).attr('href');

       if(link != '#'){
           window.open(link);
       }
   });
});
</script>

I tested this on my page, every link on the site works normally, and all of the gallery summary block links now open in a new browser window.

NOTE: if you are using multiple gallery summary blocks on one page, this code snippet will affect ALL of them... so if you only want to have it affect one particular gallery summary block, you will need to specifically call out that gallery summary block in the page snippet.

This is the section of code you would need to change in the snippet:


$('.sqs-gallery-container a').click(function(event) {

In my case, the gallery summary block I needed to change was the 2nd of 3 on my index page. I viewed the page in Preview mode, then right-clicked and selected"View Source"... then scrolled (and scrolled... and scooooolllled) until I found which gallery summary block it was (summary-thumbnail-container) and edited the code snippet to reference that block specifically:


<script>
   $(document).ready(function() {
       $('.summary-thumbnail-container').click(function(event) {
           event.preventDefault(); // preventDefault first
           var link = $(this).attr('href');

           if(link != '#'){
               window.open(link);
           }
       });
   });
   </script>

I saved and previewing my page, and bah-da-bing, just the intended gallery summary block opened links in external browser windows, leaving the other gallery blocks alone and not affecting any other links on my page.

Advanced coders (who didn't start out web coding in good ol' html waaaaay back when dinos ruled the planet) - feel free to chime in on suggestions/improvements to this method, as I am not familiar with this scripting language, but managed to muddle around with things to make it work (as far as I can tell...... if it does something wonky I will post an update).

Hope this helps someone else! :)

Link to comment
  • 2 months later...
  • 1 year later...
On 9/18/2018 at 10:20 AM, talex said:

<script> $(document).ready(function() { $('.summary-thumbnail-container').click(function(event) { event.preventDefault(); // preventDefault first var link = $(this).attr('href'); if(link != '#'){ window.open(link); } }); }); </script>

Thank you for this! It's what I've been looking for 😉 

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.