How to create download link using anchor tag in HTML?


I have a link of File created on amazon s3, now I would like to create a link to download the file inside table <td>, so How can I create download link using anchor tag <a> in HTML?


Asked by:- jaiprakash
0
: 3126 At:- 11/20/2018 2:22:14 PM
HTML download-link-using-anchor-tag download







2 Answers
profileImage Answered by:- manish

It is easy to create download link using anchor tag using HTML 5 "download" attribute, here is an example

<a href="/yourURLHere" download> click to download <a/>

You can also specify the Filename of the file, which user will download as an example here

<a href="/long/file/url" download="fileName">
 Download with Filename
</a>
  • 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. There are no restrictions on allowed values, and the browser will automatically detect the correct file extension and add it to the file (.img, .pdf, .txt, .html, etc.).
  • If the value is omitted, the original filename is used.

Download attribute is supported by all major browsers like Chrome/Firefox, supported in IE 13 and above, safari 10.1 and above, Opera 15.0 and above.

2
At:- 11/22/2018 8:07:53 AM
Thanks works as needed. 0
By : jaiprakash - at :- 11/29/2018 3:57:24 PM


profileImage Answered by:- bhanu

Simply use the "download" attribute of HTML5 to create download link

 <a href="https://example.com/fileToDownload.pdf" download="filename">Download</a>

OR you can open link in new tab using code below to view file in browser 

 <a href="https://example.com/fileToDownload.pdf" target="_blank">View</a>

target="_blank" is used to open link in new tab, so if you want to open files like PDF/Jpeg/png file in browser.

0
At:- 8/25/2021 3:54:36 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use