Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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>
like image 791
Abdullah Shoaib Avatar asked Feb 19 '18 06:02

Abdullah Shoaib


2 Answers

It indeed depends on several factors:

  • the server response Content-Disposition 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

For example 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.

like image 65
Christophe Roussy Avatar answered Sep 20 '22 13:09

Christophe Roussy


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.

like image 33
Mr Lister Avatar answered Sep 21 '22 13:09

Mr Lister