Which file types can be viewed in browser (inline, without a plugin)

一笑奈何 提交于 2019-12-07 13:40:30

问题


I just want to know which file types (like .png, .pdf, .txt) can be viewed in browser (like Chrome, Firefox). Because sometimes when i click on file link, instead of displaying in browser it download automatically. Why this happens ? Below is my code. Any help will be appreciated.

<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>

回答1:


In normal cases, following files can be viewed in browser.

.PNG .JPEG .PDF .doc etc ...

and following files will always be download.

.zip .exe etc ...

But in special cases, it depends on user browser settings and preference. You can get further details from this link.




回答2:


There are two aspects to this issue.

  1. There are addons you can add on to the browsers to allow viewing virtually anything in the browser window. In the case of PDF, for instance Firefox can't show those by default, but you can install an addon. Or, there are standalone PDF viewers that also come with such an add-on which you can activate if desired.

  2. And when you've done that, as noticed in the comments, if the resource is marked as download, the browser will download it instead of trying to open it, no matter the file type.
    Ditto if it has a http header of Content-Disposition: attachment.
    So don't use that.




回答3:


It indeed depends on several factors:

  • the server response Content-Type header value inline (open it) vs attachment (classic download)
  • the browser configuration (how to behave for various file types)
  • installed browser plugins
  • the ability of the browser to open the file

A detailed technical explanation can be found here: https://superuser.com/questions/1277819/why-does-chrome-sometimes-download-a-pdf-instead-of-opening-it

Firefox can open most PDF files (but generally not advanced forms, encrypted files ...),

  • 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 (about browser PDF reading)

Most advanced PDF features will require the user of Acrobat Reader or a special Acrobat Reader plugin. For



来源:https://stackoverflow.com/questions/48860620/which-file-types-can-be-viewed-in-browser-inline-without-a-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!