lets say i have some url to a image on the web. lets say…
url is “http://hd.wallpaperswide.com/thumbs/abstract_crystal_structure-t2.jpg“
Now I want when a user press a download button, he the image will be downloaded.
I’ve tried this..
window.location.href = Link;
But sometimes it just opens the image on the browser..
sometimes download is provided as it’s expected.
How to achieve..
Assuming a HTML5/ES5 browser, you can make use of the download attribute of the
<a>element.<a>to your desired filename.If you’re already using an
<a>as your download button, you don’t have to simulate the click, just use that element.Please see my answer here for more, remember you don’t need to do any dataURI stuff as you have a direct link.