HTML5 is the greatest version of HTML ever! (Well, at least until the next awesome version comes out). I just learned how trivially easy it is to force downloads with HTML5.
I was just trying to force a download of a PDF file because the customers need to sign it and send it back and it’s harder to do that online. I was going to use JavaScript, but decided that I’d do a quick search in case there was a better way.
Forcing Downloads is Easy—HTML5 to the Rescue!
Not only is there a better way, but it’s trivially easy to implement. I just add the keyword download
to my anchor and BAM! the browser will pop a dialog box. I haven’t tested it in a lot of browsers (or devices), but it’s still huge! I mean, as a fallback I can attach a download function only to links that have the download
keyword in them.
Now my download links look like this:
<a href="link to file" download="">Download the PDF</a>
I’m practically crying, I love HTML5 so much!!!