我只想知道哪些文件类型(如 .png、.pdf、.txt)可以在浏览器(如 Chrome、Firefox)中查看。因为有时当我点击文件链接时,它不会在浏览器中显示,而是自动下载。为什么会这样?下面是我的代码。任何帮助将不胜感激。
<script>
function openPDF(url){
var w=window.open(url, '_blank');
w.focus();
}
</script>
<a href="burger1.jpg" target='_blank'>link</a>
<div onclick="openPDF('1.pdf');">PDF 1</div>
最佳答案
这确实取决于几个因素:
- 服务器响应
Content-Disposition
header 值inline
(打开它)与attachment
(经典下载) - 浏览器配置(如何处理各种文件类型)
- 已安装的浏览器插件
- 浏览器打开文件的能力
可在此处找到详细的技术说明:https://superuser.com/questions/1277819/why-does-chrome-sometimes-download-a-pdf-instead-of-opening-it
例如 Firefox 可以打开大多数 PDF 文件(但一般不能打开高级表单、加密文件...),
- https://support.mozilla.org/en-US/kb/view-pdf-files-firefox
- https://support.google.com/chrome/answer/6213030?hl=en
- https://helpx.adobe.com/lu_en/acrobat/kb/open-in-acrobat-reader-from-chrome.html
- https://www.investintech.com/resources/blog/archives/3684-view-pdf-files-mozilla-firefox.html (关于浏览器PDF阅读)
大多数高级 PDF 功能需要使用 Acrobat Reader 或特殊的 Acrobat Reader 插件。
关于html - 可以在浏览器中查看哪些文件类型(内联,无需插件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48860620/