Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download an image instead of opening it in new tab

I am trying to download an image on click and using "download" attribute of HTML5 for this. But it is redirecting the user to a new tab instead of downloading the image.

<a href="http://upload.wikimedia.org/wikipedia/commons/3/3f/Stephenson%27s_Rocket_drawing.jpg" download="myfile.jpg">Click to Download</a>

How can I sort out this issue?

like image 625
Amrinder Singh Avatar asked Oct 22 '25 22:10

Amrinder Singh


2 Answers

I tried to change the path from the href attribute to download and it worked <a href="" download="http://upload.wikimedia.org/wikipedia/commons/3/3f/Stephenson%27s_Rocket_drawing.jpg">Click to Download</a>

like image 59
Beknazar Kashkaraliev Avatar answered Oct 25 '25 14:10

Beknazar Kashkaraliev


Most browser (Chrome, Firefox) block download from CORS origin (external domains) for safety reasons.

So instead of a "silent" download, they force the user to navigate to the screen.

-source

like image 40
Andre Goulart Avatar answered Oct 25 '25 15:10

Andre Goulart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!