-1

I'm trying to download my immgae with the HTML "download" attribute. When I click on the image, however, the preview opens and does not download it. How can I do?

<a href="img/qrcode.png" download="qrcode.png">
   <img src="img/qrcode.png" width="300" height="300">
</a>

If I leave the URL blank it downloads it, but when I go to open the photo from the downloads it gives me that it is a damaged file

karlcess
  • 43
  • 6
  • I just tested that code and, when I clicked on the image, the image was downloaded. I can't reproduce the problem. (Maybe you are dealing with a `file:` scheme URL where cross-origin files prevent the download attribute from working, but it would be pointless to download something from the local file system so that seems unlikely) – Quentin Oct 14 '20 at 18:43
  • @Quentin If I leave the URL blank it downloads it, but when I go to open the photo from the downloads it gives me that it is a damaged file – karlcess Oct 14 '20 at 18:59
  • It seems like this may be an issue with your device or browser, not your code. You've written everything in the correct form, so this issue of a preview popping up must be browser-related? Also, when you leave the URL blank and successfully download the file, does adding ".png" to the end of the filename make the file openable? On certain devices/OS, it's necessary to include the file extension. – Hello World Oct 14 '20 at 19:44
  • Does this answer your question? [Force to download image instead of opening url link to image](https://stackoverflow.com/questions/49736214/force-a-download-to-download-image-instead-of-opening-url-link-to-image) – Yevhenii Bahmutskyi Jun 29 '21 at 11:55

1 Answers1

-1

The download attribute does not need any value, as it is in W3school:

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

unless you want to change the name:

<a href="/images/myw3schoolsimage.jpg" download="w3logo">