I've a link to a PDF file in my page.
Safari opens the pdf file directly in the website. I would like to download it instead.
I've tried to add target="_blank"
to <a>
element, but it doesn't work if the pop-ups are disabled in the browser settings.
How can I solve this?
thanks
Click “Site Settings” on the right. Scroll down in Site Settings and click “Additional content settings” at the very bottom. In the expanded menu, select “PDF documents.” Toggle on the “Download PDF files instead of automatically opening them in Chrome” option.
Save / Save As optionCreate a link to download the file on the web page using the <A HREF> HTML tag. Then, recommend to the web page viewer that they right-click the link and choose the option to Save or Save as the file. Viewers can then download and save the file to their computer.
To trigger a file download on a button click we will use a custom function or HTML 5 download attribute. The download attribute simply uses an anchor tag to prepare the location of the file that needs to be downloaded.
In most browsers, clicking on the link will open the file directly in the browser. But, if you add the download attribute to the link, it will tell the browser to download the file instead. The download attribute works in all modern browsers, including MS Edge, but not Internet Explorer.
To make so, you need to change headers for .PDF files.
So, in your .htaccess, you need to do like this:
AddType application/octet-stream .pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With