34

Why is this not working:

download.html

<a href="jsplogin.jar">download</a>

The jsplogin.jar file is in the same folder has the download.html file.

when I click the download link the file jsplogin.jar should download but its trying to open the file in the browser. when I right clicked on the link and selected "save link" nothing is happening.

Coder17
  • 767
  • 4
  • 11
  • 30

3 Answers3

91

In HTML5, in most browsers you can add a 'download' attribute to the a element.

for example:

<a href="http://www.example.com/index.html" download>Download</a>

Based on this question. How can I create download link in html?

Community
  • 1
  • 1
captainrad
  • 3,760
  • 16
  • 41
  • 74
  • 4
    the download attribute does not work on Safari. And there is no plans for supporting in the future. http://caniuse.com/#feat=download Safari is no less than IE is some sense – detj Aug 13 '14 at 14:50
  • 3
    This is not working in mozilla firefox. It is redirecting me back to a new tab when i anchor a .jpg file – bibliophilsagar Oct 13 '15 at 09:57
  • 9
    @catch22 https://caniuse.com/#feat=download (just tested it in edge and firefox on windows myself and it worked) it's important to note that this attribute only works for same-origin URLs. – captainrad Nov 07 '18 at 02:32
4

Use the "download" attribute:

<a href="jsplogin.jar" download>download</a>
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
kallayya Hiremath
  • 3,560
  • 1
  • 13
  • 14
  • This is not creating a blob automatically. the href link is the link of the file in the backend server. So instead of creating a blob it is displaying it in browser. – Pran Kumar Sarkar Aug 15 '20 at 09:09
4

The download attribute didn't work for me, but this did:

<a href="myfile.csv" target="_blank">Download</a>

The opens a new tab but downloads the file and closes the tab once it realizes it's not a file type it should render. In my case it was a .csv, I did not test with .jar but i imagine you'd get the same result.

stackPusher
  • 6,076
  • 3
  • 35
  • 36