Is there any way to specify a suggested filename when using data: URI?

MontyGomery picture MontyGomery · Nov 12, 2008 · Viewed 173.7k times · Source

If for example you follow the link:

data:application/octet-stream;base64,SGVsbG8=

The browser will prompt you to download a file consisting of the data held as base64 in the hyperlink itself. Is there any way of suggesting a default name in the markup? If not, is there a JavaScript solution?

Answer

Dan Fabulich picture Dan Fabulich · Aug 4, 2011

Use the download attribute:

<a download='FileName' href='your_url'>

Live example on html5-demos.appspot.com/....

The download attribute works on Chrome, Firefox, Edge, Opera, desktop Safari 10+, iOS Safari 13+, and not IE11.