Jump to content

Auto download of PDF from a button

Recommended Posts

Posted (edited)

Dear forum. I'm looking to make the buttons on my site automatically download the linked PDF. At present, it simply opens the PDF in a new window but I'd like the file to automatically download instead when the button is clicked. Is this possible?

Thanks in advance

Edited by Sparkly-wonder
Posted

The way PDFs are treated is usually determined by the browser on whichever device is being used. It's not something you can enforce from your website. Each visitor will have their own settings.

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional.

Posted

Thanks for the reply. I've managed to find CSS code that lets the PDF auto download to happen from the header. I was hoping someone might be able to direct me as to how I could place that code into a button rather than happening when a page loads which the current code does. The code that works in the header is below:

<script>
var link = document.createElement('a');
link.href = '/s/filename.pdf';
link.download = 'filename.pdf';
link.dispatchEvent(new MouseEvent('click'));
</script>

 

 

  • 2 weeks later...
  • 6 months later...
Posted
On 3/28/2024 at 6:37 PM, Sparkly-wonder said:

Thanks for the reply. I've managed to find CSS code that lets the PDF auto download to happen from the header. I was hoping someone might be able to direct me as to how I could place that code into a button rather than happening when a page loads which the current code does. The code that works in the header is below:

<script>
var link = document.createElement('a');
link.href = '/s/filename.pdf';
link.download = 'filename.pdf';
link.dispatchEvent(new MouseEvent('click'));
</script>

 

 

You should share your site URL so we can provide exact solution

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox - PDF Lightbox popup - ...) </>  🗓️ Delivery Date Picker (Date picker form field)
Gallery block 7.1 workaround </> No-code customisations for Squarespace

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.