Sometimes, we want to force download of a base64 image with JavaScript.
in this article, we’ll look at how to force download of a base64 image with JavaScript.
How to force download of a base64 image?
To force download of a base64 image with JavaScript, we add the download
attribute to the anchor element.
For instance, we write
<a href="data:image/jpeg;base64,/9j/4AAQSkZ..." download="filename.jpg">
download
</a>
to add the anchor element with the href attribute set the base64 image URL.
And we add the download
attribute and set it to the file name of the downloaded image to let users download the image when the link is clicked.
Conclusion
To force download of a base64 image with JavaScript, we add the download
attribute to the anchor element.