Jump to content

Open ALL pdfs in new tab instead of downloading

Recommended Posts

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

On this website, some of the pdfs open in new tabs, while some are being downloaded. This seems inconsistent to me, because I link all pdfs in markdown with 

<a href="/s/link-to-.pdf" target="_blank">Linktext</a>

However, the behavior of the pdfs changes, seemingly randomly. For example, when clicking on "DEMAND FOR ELECTRICITY ON THE GLOBAL ELECTRIFICATION FRONTIER", the pdf opens in a new tab, but for "WHY DO PEOPLE STAY POOR?", it downloads. I'm using Google Chrome, but I want the behavior to be the same across all modern browsers.

I have already tried to force this with a site-wide code injection, but it didn't work.

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>
$('a[href*="pdf"]').click(function(e) {
    e.preventDefault(); // stop the existing link from firing
    var documentUrl = $(this).attr("href"); // get the url of the pdf
    window.open(documentUrl, '_blank'); // open the pdf in a new window/tab
  });
</script>

 

Link to comment
  • 2 years later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

On 8/31/2023 at 1:42 PM, LindaBee said:

Did you ever find a solution to this? I'm having the same issue

Can you share link to page where you have problem? We can take a look

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

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

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.