Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Offer files for download in HTML5

DZone's Guide to

Offer files for download in HTML5

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

The new attribute download for <a> tags allows one to offer a file for download – instead of displaying it in the browser.

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.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Published at DZone with permission of Axel Rauschmayer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}