我想通过点击链接开始下载图片。
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的下载属性(强制浏览器在点击链接后保存文件),但是我不想使用它因为它不会在旧版本的浏览器中工作。 我尝试过这个方法: 使用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下载链接的图片吗?
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点击链接下载图像
发布评论