was successfully added to your cart.

Force a file to download when link is clicked

By 14th May 2015 Blog

So here’s a little simple snippet when you want to force a download when a file such as a PDF, .doc etc is clicked.

Normal actions will open the document in the either the same browser window, or in a new tab/window by using the usual target methods:

Open file in same window:

<a href="myfile.pdf" target="_self">Click to Download</a>

Open file in new window:

<a href="myfile.pdf" target="_blank">Click to Download</a>

 

However, if you want to force the file to download, by prompting a download pop-up box (to open or save), then all you need to do is add ‘download’ to the <a> link as seen below:

Force file download window:

<a href="myfile.pdf" download>Click to Download</a>

 

Voila! easy little tip. Hope this helps!

About Phil

I'm a Wordpress web developer and website designer based in Cheshire, UK. I specialise in Wordpress, Responsive design and website conversion. | Twitter | Linkedin

6 Comments

Leave a Reply