How to download file when clicking on the link?

In HTML5 <a> tag has a new "download" attribute.

Eg:
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOnMX9PJG1f6KhXAbFuFFGo-fJvtobDN6CoeiZhG5mK8rS_lA3EIoTe-RaZPLhJZ7lvSJ-1k4gOvQ9O7nahKIJmF7Bikg6EZWPZeDor9iLFk0hsgHiiKnUbs6TJcSbxEZ9aEKkx5QOh2Ys/s1600/HeaderLogo.png" download>
In the above example the image will be downloaded when a user clicks on the hyperlink.

The 'download' attribute will work with .pdf, .txt, .html, etc. file extensions.

Final code and demo is here


Demo

No comments:

Post a Comment