Download image with JavaScript

As @Ian explained, the problem is that jQuery’s click() is not the same as the native one.

Therefore, consider using vanilla-js instead of jQuery:

var a = document.createElement('a');
a.href = "https://stackoverflow.com/questions/17311645/img.png";
a.download = "output.png";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);

Demo

Leave a Comment