Sparkly-wonder Posted March 27 Posted March 27 (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 March 27 by Sparkly-wonder
paul2009 Posted March 27 Posted March 27 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. Ziggy 1 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.
Sparkly-wonder Posted March 28 Author Posted March 28 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> Beyondspace 1
Beyondspace Posted October 22 Posted October 22 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment