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

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

问题描述

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

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





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

解决方案

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



这表示下载属性是仅支持Firefox,Chrome,Opera和最新版本的黑莓浏览器。



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

 内容类型:应用程序/八位字节流
内容处理:附件;文件名= \filename.xxx\

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


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

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

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.

解决方案

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

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

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\"

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

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

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