Howto open PDF files in same browser window?

Continuing the discussion from Treat all links as target_blank?

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:

Big thanks so far and
wish you all a pleasant weekend :sunny:

2 Likes

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

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:


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

2 Likes

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…

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.

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

… my Safari opens it, there’s no download

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.

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

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) 

2 Likes

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

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 ?

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?

No, I meant that the Nginx proxy of your discourse instance somewhere does this trick:
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?

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

Discourse uses X-Accel-Redirect for the downloads.

2 Likes

This might be helpful:

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

Were can I find the environment controller file?

Is there any progress on this topic ?

Unfortunately not :thumbsdown:

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

Thanks!

Hi,

Did you find a solution ?