且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

文件打开而不是在 Internet Explorer 中的 href 链接中下载

更新时间:2023-10-19 22:59:52

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)