如何浏览器确定是否要下载或显示 [英] How does browser determine whether to download or show

查看:141
本文介绍了如何浏览器确定是否要下载或显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web资源返回JSON内容与内容类型:应用程序/ JSON 。通常情况下,内容直接显示在浏览器,但有时不是,相反,下载提示的节目。

I have a web resource which returns json content with Content-Type:application/json. Usually the content is displayed in browser directly but sometimes it's not, instead, a download prompt shows.

我知道有一个头内容处置:内联/附件,可以显式地告诉浏览器是否要下载或显示。但是,如果我不指定这个头,如何浏览器决定?什么是它的战略?

I know there's a header Content-Disposition:inline/attachment which can explictly tell browser whether to download or show. But if I don't specify this header, how does browser decide? What's its strategy?

推荐答案

从Mozilla的文件类型和下载行动(重点煤矿):

From Mozilla's File types and download actions (emphasis mine):

当你点击一个链接,下载一个文件,的MIME类型决定采取行动是什么。如果你看到一个打开对话框,询问您是否要保存文件或指定的应用程序中打开它,那通常意味着你的Mozilla应用程序的不能在内部处理MIME类型,无插件安装并启用,可以处理它和你没有previously选择一个下载操作或辅助应用程序总是该类型文件的

When you click a link to download a file, the MIME type determines what action is taken. If you see an "Opening " dialog asking if you want to save the file or open it with a specified application, that normally means that your Mozilla application cannot handle the MIME type internally, no plugin is installed and enabled that can handle it and you have not previously selected a download action or helper application to always use for that type of file.

自带浏览器preconfigured处理基本的格式,如图像。插件(这可能与浏览器捆绑)加处理各种常见文件类型,如PDF文件。此外,还可以是辅助应用程序,这意味着浏览器下载,文件自动转发到应用程序(如洪流磁铁链接,打开你的BT客户端)

The browser comes preconfigured to handle basic formats like images. Plugins (which may be bundled with the browser) add handling for various common file types like pdfs. There can also be "helper applications", which means the browser downloads and forwards the file automatically to the application (such as a torrent magnet link opening your torrent client)

其他的一切,它会问,直到用户绑定一个默认的动作(如内容类型应用程序/八位字节流,你不能设置默认操作)。在其他浏览器一样。

Everything else, it will ask until a user binds a default action (if the Content-Type is application/octet-stream, you can't set a default action). The other browsers work the same.

这篇关于如何浏览器确定是否要下载或显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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