Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use HTML5 download attribute for HTML forms?

Tags:

html

forms

HTML5 introduced a nice feature for marking <a> links as download endpoints, by simply adding download attribute to the <a> tag (see description).

Is it possible to do the same for HTML forms?

Here is a simple use case for example: I have a form that requests the user for some details, and after the user submits the form the server should return a file according to these details.

like image 906
gamliela Avatar asked Sep 30 '14 07:09

gamliela


People also ask

What is download attribute in HTML5?

One of the upgrades that came with HTML5 is the Download attribute. As we know, there are many files that are not downloaded directly. For example: images, WebPages, PDF files, music files, etc. We have to right-click on images and then click on Save Image to save an image file.

What is the use of download in HTML?

Definition and Usage. The download attribute specifies that the target will be downloaded when a user clicks on the hyperlink. This attribute is only used if the href attribute is set. The value of the attribute will be the name of the downloaded file.

How do I download a file in HTML5?

Using the HTML5 Download Attribute. The download attribute is part of the HTML5 spec and expresses a link as download link rather than a navigational link. The download attribute also allows you to rename the file name upon downloading. When the file resides on the server, especially if it’s been automatically generated, ...

What is the download attribute in a PDF?

The download attribute also accepts a value that you can specify as the filename alias: When you download the document.pdf file, the browser will automatically rename the file with the download attribute value. The download attribute needs to refer to a file that has the same origin, or it won’t be executed by the browser.


2 Answers

This is not possible. According to the specification is the "download" attribute only specified for a and area.

http://www.w3.org/html/wg/drafts/html/master/links.html#downloading-resources

like image 148
yncyrydybyl Avatar answered Sep 30 '22 02:09

yncyrydybyl


No, form doesn't have a download attribute, so it is not possible to have that exact behavior with a form.

You can set the output file name through a post though, by setting the Content-Disposition HTTP header:

Content-Disposition: attachment; filename="yourPicture.png"
like image 32
Patrick Hofman Avatar answered Sep 30 '22 04:09

Patrick Hofman