Sometimes, we want to trigger a file download when clicking an HTML button
In this article, we’ll look at how to trigger a file download when clicking an HTML button.
How to trigger a file download when clicking an HTML button?
To trigger a file download when clicking an HTML button, we can set the download
attribute to the name of the downloaded file.
For instance, we write
<a href="path_to_file" download="proposed_file_name">Download</a>
to add the download
attribute to the link and set the downloaded file’s name to proposed_file_name
.
Adding the attribute will also enable downloads.
Conclusion
To trigger a file download when clicking an HTML button, we can set the download
attribute to the name of the downloaded file.