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

3

6

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>
Lyda answered 19/2, 2018 at 6:30 Comment(5)
Sometimes it downloads is because of the presence of download attribute on the link.Enlarger
apemobile.zendesk.com/hc/en-us/articles/…Anesthesiology
you need to update your browsers and adobe pdf viewer.Pali
this is hard to control because often it depends on the computer of the user viewing your page.Consanguinity
@Shree Khanal very helpful artical.Lyda
S
-5

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.

Shlomo answered 26/2, 2018 at 7:2 Comment(3)
How a browser can open doc?Violate
I think even MS IE cannot open .doc files.Diva
@Shlomo Broken linkPecoraro
D
6

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 ...),

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

Diva answered 17/9, 2019 at 10:34 Comment(1)
Thanks to @Conic for suggesting to use Disposition (I rejected the edit a bit too quickly, I use this header in my own code ...)Diva
A
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.

Aviator answered 19/2, 2018 at 7:44 Comment(1)
Firefox and Chrome have been able to open most 'simple' PDF files natively for several years. Here an article from 2013 discussing this: investintech.com/resources/blog/archives/…Diva
S
-5

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.

Shlomo answered 26/2, 2018 at 7:2 Comment(3)
How a browser can open doc?Violate
I think even MS IE cannot open .doc files.Diva
@Shlomo Broken linkPecoraro

© 2022 - 2024 — McMap. All rights reserved.