href图片链接下载点击 [英] href image link download on click
问题描述
我生成普通链接,例如:<a href="/path/to/image"><img src="/path/to/image"/></a>代码>在网络应用中.
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"
我不想要这种行为,我希望当我点击链接时弹出一个下载框,这是否可能仅使用 html 或 javascript?怎么样?
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?
如果不是,我想我将不得不编写一个 download.php 脚本并将其调用到以文件名作为参数的 href 中...?
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>
尚未完全支持 caniuse,但您可以使用 modernizr(在非核心检测下)检查浏览器的支持.
It's not yet fully supported caniuse, but you can use with modernizr (under Non-core detects) to check the support of the browser.
这篇关于href图片链接下载点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!