Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 5

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.

4 Replies
Commander Lvl 3
Message 2 of 5

Re: Not work html5 a tag href download attr.

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


- Mark
Highlighted
Copilot Lvl 2
Message 3 of 5

Re: Not work html5 a tag href download attr.

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>

 

 

Commander Lvl 3
Message 4 of 5

Re: Not work html5 a tag href download attr.

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.


- Mark
Ground Controller Lvl 1
Message 5 of 5

Re: Not work html5 a tag href download attr.

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