For the first time, HTML5 introduced new interactive features to the HTML.This HTML5 attribute provides a functionality of a force download.
Mostly you use a link for the file like images, pdf, documents, texts and generally when clicking on the link, files will be open within the browser’s new tab.HTML5 download attribute within links change behavior and allow the file to download in the browser.Basically, this attribute specifies the browser to download files rather than open the target resource in the new tab of the browser .
Initially in older browser you need to write php code to download files and this approach is very annoying so HTML5 added new download properties to change it. It can be used like this:
1 2 3 | <a href="URL" download="filename"> PDF </a> |
Here, In download attribute set the property values, you can specify the name of the resource file you want to allow to download.The value of the download attribute is a not necessary and no restrictions but make sure that its a filename.The attribute value specifies the filename that used when downloading the file.Here I used “filename” filename, not “filename.jpg” because no need to specify the file extension if you want to preserve the original name.
Through this attribute browser will download the file. You can also pass the attribute value as the null, like this:
1 2 3 | <a href="URL" download=""> PDF </a> |
At present, this property has been supported in major browsers.
This is not fiction, it actually work so use this HTML5 feature and enjoy its benefits.
NOTE: Firefox does not support automatic download if you are using different domain.It will work for same domain of file and current page.
That’s it.you are done it 🙂 Thank you for reading.Feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.
Comments (4)