I would like to start download of an image on click of a link.
<a id="downloadImage" href="imagepath">Click here to download</a>
I know we can use download attribute of HTML5 (Force a browser to save file as after clicking link) but I would not like to use it as it will not be working in older versions of browsers. I did tried the method here: Download File Using Javascript/jQuery but it opens the image in the iframe .
Can anybody help me to force a browser to download an image onclick of a link using jquery?
As far as I know there is no client-side cross-browser solution for this issue (doesn't matter using jQuery or any other UI toolkit). What you need to do in order to trigger browser to download a file is to add some HTTP headers to the server response:
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=image.jpg
This post may also be helpful for you.
You can use the download attribute, while not fully supported across browsers, you can use modernizr to support/fallback for unsupported browsers.
For supported browsers, check http://caniuse.com/#feat=download
<a href="/path/to/image.jpg" title="ImageName" download="ImageName" >
<img src="/path/to/image.jpg" alt="ImageName">
</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With