3 ms·
I've been using it with href="#", so it simply downloads the current HTML page.
by john-doe 5y ago
I've been using it with href="#", so it simply downloads the current HTML page.
- chrismorgan 5y agoShorter! <a href download>Download this page</a> (Explanation: href is equivalent to href="", and an empty string is a valid URL string, a relative URL with no scheme, no host, zero path segments, no query string and no fragment. # is a valid URL string representing the same URL, but with an empty fragment (rather than no fragment). URLs are resolved relative to what the HTML spec calls the document base URL, and relative URL resolution of an empty string against that will yield that base URL sans fragment, just as resolving # will yield that base URL with an empty fragment. Note also that you can’t just omit the href attribute, or else it won’t be a link. Also note that a <base href=…> element will affect the document base URL and is thus likely to make both of these links do the wrong thing.)