Over a million developers have joined DZone.

Offer files for download in HTML5

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

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.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

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

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}