Firefox 在选项卡中显示 .gadget 文件而不是下载
我有一个简单的 HTML 文件,它引用 .gadget,以便可以下载它:
<a href="name.gadget">Download me!</a>
IE、Opera、Safari 和 Chrome 都提供将文件保存到磁盘的功能,但是 Firefox 在选项卡中加载二进制文件。为什么 Firefox 讨厌我?我必须做什么才能强制 Firefox 提供下载对话框?
我真的不想指导用户“右键单击并选择‘文件另存为’”,或者他们必须在下载后删除 .zip 扩展名。
服务器是 Apache/2.2.17,以防相关。有趣的事实是,如果我从本地磁盘加载打开的 .html 文件,Firefox 的行为确实与所有其他浏览器一样。但是一旦它位于服务器上,它就会在选项卡中加载文件。
I have a simple HTML file which references .gadget so that it can be downloaded:
<a href="name.gadget">Download me!</a>
IE, Opera, Safari and Chrome all offer saving file to disk, however Firefox loads binary file in a tab. Why does Firefox hate me and what must I do to force Firefox to offer download dialog?
I don't really want to instruct users to "right-click and choose 'save file as'", or that they have to remove .zip extension after downloading.
Server is Apache/2.2.17, in case that it's relevant. Interesting fact is that Firefox does behave like all other browsers - if I load open .html file from local disk. But once it's on the server, it loads file in a tab.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以,这就是解决方案。
问题是 Apache 默认为所有“未知”文件类型返回 Content-Type=text/plain HTTP 标头。与所有其他浏览器不同,Firefox 遵守标准,因此它会显示内容。 这是他们对此的看法。 您可以使用 Firebug 检查 Firefox 中的标头(或者简单地使用如果您使用的是 Unix,请使用curl)。
上面的链接也提示了解决方案;向服务器注册 application/x-windows-gadget MIME 类型。如果您无权访问服务器配置,请将 .htaccess 文件放在与您的文件相同的目录中(或目录上方的任何目录中),并使用以下行:
之后,不要忘记清除浏览器缓存。
So, here's the solution.
The problem is that Apache returns Content-Type=text/plain HTTP header by default for all "unknown" file types. Firefox adheres to the standards unlike all other browsers so it displays the content. Here's what they have to say about it. You can inspect header in Firefox with Firebug (or simply use curl if you're on Unix).
The above link also hints the solution; register application/x-windows-gadget MIME type with the server. If you don't have access to the server configuration, put .htaccess file in the same directory as your file (or in any of the directories above your directory) with the following line:
After that, don't forget to clear your browser cache.