Amrinder Singh
Amrinder Singh

Reputation: 5482

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?

Upvotes: 4

Views: 6058

Answers (2)

Andre Goulart
Andre Goulart

Reputation: 596

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

Upvotes: 1

Beknazar Kashkaraliev
Beknazar Kashkaraliev

Reputation: 81

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>

Upvotes: 8

Related Questions