Offer files for download in HTML5
Join the DZone community and get the full member experience.Join For Free
Previously. Normally, when you click on an <a> tag, the web browser visits the file it refers to. Sometimes, you instead want the file to be downloaded. Most browsers usually ask the user to confirm before starting the download. Previously, you had to send the following HTTP header to make that happen.
Content-Disposition: attachment; filename=my-icon.png
Now. The new attribute download ensures that a file is downloaded and not displayed.
<a href="http://example.com/3zw1456.png" download="my-icon.png" >download me</a>Giving the attribute a value allows you to control the name of the file that is saved to disk.
Use case. This feature is especially useful if you are working with URLs coming from Blob instances (which include File instances in the user’s file system) and FileEntry instances (in browser-local sandboxed file systems). With download, their data becomes downloadable.
Source: “Downloading resources in HTML5: a[download]” by Eric Bidelman for HTML5 Rocks Updates.
Published at DZone with permission of Axel Rauschmayer, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.