Forcing a File Download

How did I not know this? I remember trying to look this up at the beginning of this project. I wanted to have a link to a pdf and force that pdf to download, not display in the browser.

And I can think of a lot of different places I might want to do this, especially when offering a pdf of a page that exists on the web already. The user doesn’t want to see it again; they want to have the pdf on their computer.

It’s incredibly easy, just add the ‘download’ attribute to your link tag:

<a href=”test.pdf” download>download the test.pdf</a>

This is where I found the answer:

Force a file to download when link is clicked

And now that I know what to look for here’s a description of the attribute:

https://www.w3schools.com/Tags/att_a_download.asp