强制用户下载的浏览器,而再打开文件的xlsx [英] force user to download rather then open xlsx file in browser

查看:101
本文介绍了强制用户下载的浏览器,而再打开文件的xlsx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些谁当他们打开我的网站上的Excel文件需要用户的青睐。如果他们simpely另存为,然后打开它的快速。
他们还在其他网站上相同的问题,所以这是对自己身边的一个问题。
不过是有没有办法强制浏览器只提供保存和不能提供开放?

We have some users who when they open an excel file on my website it takes ages. If they simpely Save as and then open it's quick. They have the same issue on other sites so it's a problem on their side. However is there a way to force the browser to only offer save and not offer open?

如这里指出的:
<一href=\"http://stackoverflow.com/questions/3841578/is-there-a-way-to-force-the-user-to-download-a-file-from-a-href-link-rather-than\">Is有没有办法强制用户从A HREF链接下载一个文件,而不是在浏览器窗口中打开它?
和这里:
强制使用PHP 下载文件
我目前使用的:

As noted here: Is there a way to force the user to download a file from a href link rather than to open it in a browser window? and here: Forcing to download a file using PHP I'm currently using:

 Response.ContentType = "application/ms-excel";
 Response.AddHeader("content-disposition", "attachment; filename=Report.xlsx");
 Response.AddHeader("Content-Length", new System.IO.FileInfo(fileName).Length.ToString());

但是,这仍然提供开放的选项。

But this is still offering the open option.

有没有办法迫使这还是纯粹依赖于用户的浏览器设置。

Is there a way to force this or is it simply dependent on the users browser settings.

推荐答案

只需发送一个不同的内容类型(应用程序/八位字节流):

Just send a different Content-Type (application/octet-stream):

Response.ContentType = "application/octet-stream";

这样,浏览器不能识别的格式,只是提出来保存文件。

This way the browser doesn't recognize the format and just proposes to save the file.

---编辑----

--- EDIT ----

今天,我认识了另一头字段,这可能解决您的问题:

Today, I got to know another header field, that probably fixes your problem:

X-Content-Type的选项:nosniff

"X-Content-Type-Options: nosniff"

描述:唯一定义的值,'nosniff',从MIME嗅探的响应远离声明内容类型$ P ​​$ pvents Internet Explorer,这也适用于谷歌浏览器,下载扩展时,[31]。

Description: "The only defined value, 'nosniff', prevents Internet Explorer from MIME-sniffing a response away from the declared content-type. This also applies to Google Chrome, when downloading extensions.[31]"

http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

这篇关于强制用户下载的浏览器,而再打开文件的xlsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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