如何强制文件浏览器,而不是下载(PDF)打开? [英] How to force files to open in browser instead of download (pdf)?

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

问题描述

有没有办法强制PDF文件浏览器中打开时,选择在浏览器中显示PDF被选中?

Is there a way to force PDF files to open in browser when the option "Display PDF in browser" is unchecked?

我尝试使用嵌入标记和一个iframe,但仅当选项被选中的作品。

I tried using embed tag and an iframe, but it only works when that option is checked.

没有任何人有一个想法,我能做些什么?

Does anybody have an idea what I can do?

推荐答案

要指示该文件应在浏览器中查看浏览器:

To indicate to the browser that the file should be viewed in the browser:

Content-Type: application/pdf
Content-Disposition: inline; filename="filename.pdf"

要下载,而不是浏览的文件:

To have the file downloaded rather than viewed:

Content-Type: application/pdf
Content-Disposition: attachment; filename="filename.pdf"

编辑:如果文件名中包含特殊字符,如文件名周围的文件名引号是必需的[1] .PDF 这可能会违反浏览器的处理响应能力

The quotes around the filename are required if the filename contains special characters such as filename[1].pdf which may otherwise break the browser's ability to handle the response.

这篇关于如何强制文件浏览器,而不是下载(PDF)打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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