Not work html5 a tag href download attr.

Please check the sources : 

<a href="http://test.com/test.png" download="test.png">Download Image</a>

I added the download option to a tag using JavaScript.

However, the download window will not appear and will be moved to the href address.

How do I force url to download from the client side?

I respect all the developers. Thank you for reading this article.

Hi,

For me it works fine in Chrome 70 for me, but you could try adding  target="_blank" to the link as a fallback.

I got the information and tested it from my side using this applet:

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_a_download

from this page:

https://www.w3schools.com/tags/att_a_download.asp

1 Like

I don’t understand.

try this code 

<a href="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" download>
  <img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" alt="W3Schools" width="104" height="142">
</a>

Works fine on my PC (Chrome 70). On an iPad, for example, this won’t work because iOS can’t “download” things like that. That is why I suggested adding target=“_blank” to the a  element. For browsers that support downloading, nothing will change. For browsers that don’t, the image wil, open in a new tab so users can manually download the file.

a [download] can no longer download resources from a different origin. See how I fixed that here
https://link.medium.com/jowNvYVBC0

2 Likes

It works for me in all the browsers of my laptop and android phone, but it is not working in iPhone browsers except safari.
In iPhone browsers (Chrome and Firefox), when I click on download, the image opened in a new tab and I have to manually give right-click for download but I want it auto-download.
Is there any settings difference in android and iPhone browsers?
How can I resolve this issue?