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?
According to RFC 2397, no, there isn't.
Nor does there appear to be any attribute of the<a>
element that you can use either.However HTML5 has subsequently introduced the
download
attribute on the<a>
element, although at the time of writing support is not universal (no MSIE support, for example)You actually can achieve this, in Chrome and FireFox.
Try the following url, it will download the code that was used.
The following Javascript snippet works in Chrome by using the new 'download' attribute of links and simulating a click.
And the following example shows it's use:
I've looked a bit in firefox sources in netwerk/protocol/data/nsDataHandler.cpp
data handler only parses content/type and charset, and looks if there is ";base64" in the string
the rfc specifices no filename and at least firefox handles no filename for it, the code generates a random name plus ".part"
I've also checked firefox log
interesting files if you want to look at mozilla sources:
I think you can stop searching a solution for now, because I suspect there is none :)
as noticed in this thread html5 has
download
attribute, it works also on firefox 20 http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#attr-hyperlink-downloadThis one works with Firefox 43.0 (older not tested):
dl.js:
dl.html
If button is clicked it offered a file named hello.bin for download. Trick is to use File instead of Blob.
reference: https://developer.mozilla.org/de/docs/Web/API/File