Coder17
Coder17

Reputation: 873

How to download file using anchor tag <a>

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.

Upvotes: 37

Views: 128141

Answers (3)

stackPusher
stackPusher

Reputation: 6512

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.

Upvotes: 5

kallayya Hiremath
kallayya Hiremath

Reputation: 4498

Use the "download" attribute:

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

Upvotes: 4

captainrad
captainrad

Reputation: 3830

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?

Upvotes: 95

Related Questions