# Howto open PDF files in same browser window?

**URL:** https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823
**Category:** Feature
**Created:** [Fevereiro 28, 2015, 3:00am UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823 "2015-02-28T03:00:39Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![terraboss](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terraboss/32/381157_2.png) [@terraboss](https://meta.discourse.org/u/terraboss)
#### Post date: [Fevereiro 28, 2015, 3:00am UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/1 "2015-02-28T03:00:39Z")

</div>

Continuing the discussion from [Treat all links as target\_blank?](https://meta.discourse.org/t/treat-all-links-as-target-blank/10988)

Hi,  
I’m using some categories for discussing / viewing pdfs (scientific reviews). I’d like to prevent Discourse / my Safari desktop browser from putting each file into my download folder. The pdf should be viewable in the current tab/window. How can I set this?

In case of visiting Discourse via iPad or any other kind of mobile device, it’s just working fine by design. But those screen resolutions are sometimes too low. Any ideas? CSS snippets?

###I found this, but I don’t know how to set this globaly:

> <https://stackoverflow.com/questions/6293893/how-do-i-force-files-to-open-in-the-browser-instead-of-downloading-pdf>

Big thanks so far and  
wish you all a pleasant weekend ☀

---

<div class="post-metadata">

### Author: ![Kuro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuro/32/38491_2.png) [@Kuro](https://meta.discourse.org/u/Kuro)
#### Post date: [Fevereiro 28, 2015, 11:14am UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/2 "2015-02-28T11:14:26Z")

</div>

Isn’t that a thing that you have to configure in Safari yourself? Changing the server-side stuff seems like the wrong approach.

Not owning a mac I google searched and got sent to the adobe-website:

[https://helpx.adobe.com/acrobat/kb/pdfs-safari-acrobat-8-mac.html](https://helpx.adobe.com/acrobat/kb/pdfs-safari-acrobat-8-mac.html)

According to other sources, the adobe-pdf-plugin itself is problematic and has to be deleted (apparently by searching for “adobe plug” without the “” in the finder and then deleting them.

Using the reverse search (for how to download pdfs instead of opening them in the browserwindow) I found this:

> <https://apple.stackexchange.com/questions/57039/how-make-safari-download-pdf-files-instead-of-opening-them-in-page>

The first reply has some code snippets. Changing the YES to a NO yields:  
`defaults write com.apple.Safari WebKitOmitPDFSupport -bool NO`

These suggestions not in any specific order. I don’t know your system configuration nor do I own a mac. Everything you try is on your own risk!

But please, don’t try to change download behaviour on the server-side. It would mean that you are making your problem into anybodies problem. And that is not the way to go.

Filed Under: [Also… google helps immensly with problems like these](#tag)

---

<div class="post-metadata">

### Author: ![JSey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jsey/32/3540_2.png) [@JSey](https://meta.discourse.org/u/JSey)
#### Post date: [Fevereiro 28, 2015, 1:09pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/3 "2015-02-28T13:09:27Z")

</div>

I’ve just tested this with a somewhat vanilla Discourse install and Safari: here, Safari opens all PDF documents instead of downloading them. So either your Safari, or the site settings of that Discourse instance seem to be the culprit…

---

<div class="post-metadata">

### Author: ![terraboss](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terraboss/32/381157_2.png) [@terraboss](https://meta.discourse.org/u/terraboss)
#### Post date: [Fevereiro 28, 2015, 1:41pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/4 "2015-02-28T13:41:24Z")

</div>

I’m using Safari Version 8.

I didn’t found any client side option to force view pdfs in browser. Actually, I noticed the same behaviour on Firefox and Chrome as well. All of them are downloading the pdfs. Thats very annoying in long term. And I didn’t wanna use third-party pdf viewer e.g. Adobe Acrobat. I want it natively.

---

<div class="post-metadata">

### Author: ![JSey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jsey/32/3540_2.png) [@JSey](https://meta.discourse.org/u/JSey)
#### Post date: [Fevereiro 28, 2015, 1:52pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/5 "2015-02-28T13:52:13Z")

</div>

Strange indeed. Version 8 is running here, too. What happens if you follow this link: [http://www.education.gov.yk.ca/pdf/pdf-test.pdf](http://www.education.gov.yk.ca/pdf/pdf-test.pdf)

… my Safari opens it, there’s no download

---

<div class="post-metadata">

### Author: ![terraboss](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terraboss/32/381157_2.png) [@terraboss](https://meta.discourse.org/u/terraboss)
#### Post date: [Fevereiro 28, 2015, 2:23pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/6 "2015-02-28T14:23:42Z")

</div>

Me too.

That’s what I’m looking for… and that’s why I think it’s Discourse specific and not on my client side.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [Fevereiro 28, 2015, 2:25pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/7 "2015-02-28T14:25:05Z")

</div>

Do the problem files have the HTTP header  
Content-Type application/pdf  
or only the “.pdf” file extension?

---

<div class="post-metadata">

### Author: ![terraboss](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terraboss/32/381157_2.png) [@terraboss](https://meta.discourse.org/u/terraboss)
#### Post date: [Fevereiro 28, 2015, 2:33pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/8 "2015-02-28T14:33:29Z")

</div>

I don’t know. They are just normal pdf files. Nothing else.  
Drag & Drop attachments with file size indication in brackets.

```
<a class="attachment" href="/uploads/default/25/6a56acaef61ec7ef.pdf">Filename.pdf</a> (file size KB) 

```

 ![](https://global.discourse-cdn.com/meta/original/3X/b/0/b0f00e6f29f9fc02803d0b9c414a5de3e0722832.png) 

![](https://global.discourse-cdn.com/meta/original/3X/d/c/dc580cf41084d274169550d01f8203e07f8176ca.png)

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [Fevereiro 28, 2015, 3:25pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/9 "2015-02-28T15:25:37Z")

</div>

I just tried on my localhost Discourse with a dragged-dropped 141.8KB file and clicking on the attachment link opened it in the browser.

It had the correct Content-Type

I thought it might be the spaces in the file name, but the file I tried had spaces too.

My best guess is that it is not a Discourse thing, but a browser setting. eg. Firefox  
Tools → Options → Applications

![](https://global.discourse-cdn.com/meta/original/3X/0/6/06f747d3126f8ba1f290de189d0c8cba0c953765.png)

---

<div class="post-metadata">

### Author: ![terraboss](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terraboss/32/381157_2.png) [@terraboss](https://meta.discourse.org/u/terraboss)
#### Post date: [Fevereiro 28, 2015, 4:42pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/10 "2015-02-28T16:42:20Z")

</div>

It’s not a client side issue / feature. This happens only on Discourse. With ALL browsers. On other sites were pdfs are directly linked to any kind of server path url working fine.

Until now, I didn’t found anything specific in Github by searching `class="attachment" `.

Maybe some stuff member know how to perform a force open in browser window. @codinghorror ?

---

<div class="post-metadata">

### Author: ![JSey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jsey/32/3540_2.png) [@JSey](https://meta.discourse.org/u/JSey)
#### Post date: [Fevereiro 28, 2015, 6:05pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/11 "2015-02-28T18:05:50Z")

</div>

It might be something on the Ngnix side - if there’s no hidden Discourse setting which you can mis-configure to create this behavior.

---

<div class="post-metadata">

### Author: ![terraboss](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terraboss/32/381157_2.png) [@terraboss](https://meta.discourse.org/u/terraboss)
#### Post date: [Fevereiro 28, 2015, 11:35pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/12 "2015-02-28T23:35:32Z")

</div>

> [@JSey](#):
>
> It might be something on the Ngnix side - if there’s no hidden Discourse setting which you can mis-configure to create this behavior.

I don’t know. The download folder isn’t just normal folder as I can see. It’s something script-based magic for me that requests login credentials if you’re not loged into the system, some kind of file manager. Is this part of Ngnix? Is it possible to change this behaviour?

---

<div class="post-metadata">

### Author: ![JSey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jsey/32/3540_2.png) [@JSey](https://meta.discourse.org/u/JSey)
#### Post date: [Março 1, 2015, 10:17am UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/13 "2015-03-01T10:17:51Z")

</div>

No, I meant that the Nginx proxy of your discourse instance somewhere does this trick:  
[http://mikepricetw.com/force-file-download-nginx-apache/](http://mikepricetw.com/force-file-download-nginx-apache/)  
…which would force the download. Are you running a standard Docker install with everything on the latest version?

---

<div class="post-metadata">

### Author: ![terraboss](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terraboss/32/381157_2.png) [@terraboss](https://meta.discourse.org/u/terraboss)
#### Post date: [Março 1, 2015, 11:03am UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/14 "2015-03-01T11:03:04Z")

</div>

Yes, one install on Amazon AWS and another on Digital Ocean. Both are default Docker installs under Ubuntu 14.04

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [Março 1, 2015, 8:40pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/15 "2015-03-01T20:40:14Z")

</div>

Discourse uses [X-Accel-Redirect](http://wiki.nginx.org/XSendfile) for the downloads.

---

<div class="post-metadata">

### Author: ![terraboss](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terraboss/32/381157_2.png) [@terraboss](https://meta.discourse.org/u/terraboss)
#### Post date: [Março 1, 2015, 9:49pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/16 "2015-03-01T21:49:18Z")

</div>

This might be helpful:

> <https://stackoverflow.com/questions/16208738/display-attached-pdf-in-browser-within-iframe-rails/16209051#16209051>

```
... :disposition => 'inline', :type => "application/pdf")

```

Were can I find the environment controller file?

---

<div class="post-metadata">

### Author: ![thoka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thoka/32/115652_2.png) [@thoka](https://meta.discourse.org/u/thoka)
#### Post date: [Fevereiro 21, 2017, 9:31pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/17 "2017-02-21T21:31:46Z")

</div>

Is there any progress on this topic ?

---

<div class="post-metadata">

### Author: ![terraboss](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terraboss/32/381157_2.png) [@terraboss](https://meta.discourse.org/u/terraboss)
#### Post date: [Fevereiro 21, 2017, 9:47pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/18 "2017-02-21T21:47:17Z")

</div>

Unfortunately not 👎

---

<div class="post-metadata">

### Author: ![terraboss](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/terraboss/32/381157_2.png) [@terraboss](https://meta.discourse.org/u/terraboss)
#### Post date: [Dezembro 3, 2017, 9:51pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/19 "2017-12-03T21:51:52Z")

</div>

> [@codinghorror](#):
>
> File attachments should download as attachments. That is as designed.

Can someone help me to find the right ngix setting, where I can define a exception for force downloading PDF files?

Thanks!

---

<div class="post-metadata">

### Author: ![ufukayyildiz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ufukayyildiz/32/217157_2.png) [@ufukayyildiz](https://meta.discourse.org/u/ufukayyildiz)
#### Post date: [Março 23, 2019, 6:29pm UTC](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823/20 "2019-03-23T18:29:21Z")

</div>

Hi,

Did you find a solution ?

[Próxima página](https://meta.discourse.org/t/howto-open-pdf-files-in-same-browser-window/25823.md?page=2)
