简体   繁体   English

检测浏览器是否可以显示 pdf 内联

[英]Detect if a browser can display a pdf inline

How can I make sure a browser is capable of displaying a pdf inline?如何确保浏览器能够显示 pdf 内联? I used to check the navigator mime type like this:我曾经像这样检查导航器 mime 类型:

if (navigator && navigator.mimeTypes && navigator.mimeTypes['application/pdf'])

However this fails in Firefox 52. For my use case I don't need to know this before the pdf file is loaded, so maybe I can check for content inside the embed tag or something similar?然而,这在 Firefox 52 中失败了。对于我的用例,在加载 pdf 文件之前我不需要知道这一点,所以也许我可以检查 embed 标记或类似内容中的内容?

I might be a tad late to the party, but I had the same problem and stumbled upon this:我参加聚会可能有点晚了,但我遇到了同样的问题,偶然发现了这个:

§ 8.9.1.6 PDF viewing support § 8.9.1.6 PDF 查看支持

window.navigator.pdfViewerEnabled

Returns true if the user agent supports inline viewing of PDF files when navigating to them, or false otherwise.如果用户代理在导航到 PDF 文件时支持内联查看,则返回true ,否则返回false In the latter case, PDF files will be handled by external software.在后一种情况下,PDF 文件将由外部软件处理。

Browser compatibility table浏览器兼容性表

After MDN web docs article :MDN 网络文档文章之后: 支撑台

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM