I generate normal links like: <a href="/path/to/image"><img src="/path/to/image" /></a>
in a web app.
When I click on the link, it displays the picture in a new page. If you want to save the picture, then you need to right click on it and select "save as"
I don't want this behaviour, I would like to have a download box popping out when I click on the link, is that possible just with html or javascript? How?
If not I guess I would have to write a download.php script and call it into the href with the file name as parameter...?
<a download="custom-filename.jpg" href="/path/to/image" title="ImageName">
<img alt="ImageName" src="/path/to/image">
</a>
It's not yet fully supported caniuse, but you can use with modernizr (under Non-core detects) to check the support of the browser.
The easiest way of creating download link for image or html is setting download attribute, but this solution works in modern browsers only.
<a href="/path/to/image" download="myimage"><img src="/path/to/image" /></a>
"myimage" is a name of file to download. Extension will be added automatically Example here
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