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.
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.
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.
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, ...
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.
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
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With