强制浏览器下载使用jQuery的一个链接的点击图片 [英] Force browser to download an image on click of a link using jquery
问题描述
我想上的链接的点击开始图像的下载。
I would like to start download of an image on click of a link.
<a id="downloadImage" href="imagepath">Click here to download</a>
我知道我们可以使用HTML5的下载属性(<一个href=\"http://stackoverflow.com/questions/11353425/force-a-browser-to-save-file-as-after-clicking-link\">Force浏览器文件另存为点击链接后),但我不希望使用它,因为它不会在旧版本的浏览器来工作。
我在这里做试过的方法:
下载文件使用JavaScript / jQuery的
但它开启了图像中的iframe中。
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 .
任何人可以帮助我,迫使浏览器中使用jQuery的下载链接的图像的onclick?
Can anybody help me to force a browser to download an image onclick of a link using jquery?
推荐答案
据我知道有此问题没有客户端的跨浏览器的解决方案(没关系使用jQuery或任何其他UI工具包)。您需要什么才能触发浏览器下载文件做的是一些HTTP头添加到服务器响应:
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.
这篇关于强制浏览器下载使用jQuery的一个链接的点击图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!