Get #Amazon #Prime for this #holiday #amazonprime #christmas #2019

How to set the name of a to-be-download file? #javascript #html

By Jun - Support me on Amazon Canada

To set the name of a file (image, audio etc) to be downloaded / saved from your webpage, you can use a download attribute of anchor element if the file is sent from your web server. (same origin)

What is same origin? 

Taken from MDN doc: same-origin policy, it means the following: 
Two pages have the same origin if the protocol, port (if one is specified), and host are the same for both pages. 

How to do it?

Thanks to this StackOverflow answer, by setting download attribute of your anchor element, you can set your file name.
<a download="logo.gif" href="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">Download transparent png</a> 

References: