文件打开而不是在 Internet Explorer 中的 href 链接中下载 [英] File opens instead of downloading in internet explorer in a href link

查看:30
本文介绍了文件打开而不是在 Internet Explorer 中的 href 链接中下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<a href="path/to/file/filename.xxx" download="filename.xxx">filename</a>'

当我点击链接时,我的 filename.xxx 应该会被下载.

When i click the link, my filename.xxx should be downloaded.

它在 chrome 中完美运行.但是在 Internet Explorer 中,它会打开文件而不是下载文件.可能是什么问题呢?是否有任何要添加的属性以使其在 ie 中工作.

It works perfectly in chrome. But in Internet explorer, it opens the file instead of downloading. What could be the problem? Is there any properties that is to be added to make it work in ie.

而且我还需要一个适用于所有浏览器的文件下载示例.

And also i need a file download sample that works for all the browsers.

推荐答案

download 属性在 IE 中不受支持(请参阅 http://caniuse.com/#search=download%20attribute).

The download attribute is not supported in IE (see http://caniuse.com/#search=download%20attribute).

这表明只有 firefox、chrome、opera 和最新版本的黑莓浏览器支持下载属性.

That suggests the download attribute is only supported by firefox, chrome, opera and the latest version of blackberry's browser.

对于其他浏览器,您需要使用更传统的方法来强制下载.也就是说,服务器端代码对于设置适当的 Content-Type 和 Content-Disposition 标头来告诉(或根据您的观点进行欺骗)浏览器下载项目是必要的.标题应如下所示:

For other browsers you'll need to use more traditional methods to force download. That is server side code is necessary to set an appropriate Content-Type and Content-Disposition header to tell (or trick depending on your point of view) the browser to download the item. Headers should look like this:

Content-Type: application/octet-stream
Content-Disposition: attachment;filename="filename.xxx"

(感谢 antyrat 复制和粘贴标题)

(thanks to antyrat for the copy and paste of the headers)

这篇关于文件打开而不是在 Internet Explorer 中的 href 链接中下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆