Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening files in browser instead of downloading

Tags:

html

pdf

I have a href link to a pdf file that when clicked on it downloads. I want this to just open in a new page instead of downloading.

<a href="../file/1012">clicking here</a>

I've had a look at a website that does this with iframe, but I would prefer not to use that.

like image 555
kurupt_89 Avatar asked Sep 01 '11 07:09

kurupt_89


People also ask

How do I open a file in browser instead of downloading it?

At the top right, click More Settings. At the bottom, click Show advanced settings. Under “Privacy”, click Content settings. Under “PDF Documents," check the box next to "Open PDF files in the default PDF viewer application.” (Uncheck this box if you want PDFs to open automatically when you click them.)

Why do some PDFs open in browser and some download?

Sometimes even when setting Adobe Acrobat DC as the Default, downloaded PDFs will open in Chrome instead. This is because Chrome is set to use it's integrated PDF viewer when files are downloaded by default. You will need to turn this off to make it go away.


1 Answers

Your server should return this http header:

Content-Type: application/pdf

For viewing in browser it should also return:

Content-Disposition: inline;filename="myfile.pdf"

For downloading:

Content-Disposition: attachment;filename="myfile.pdf"
like image 165
BornToCode Avatar answered Oct 07 '22 17:10

BornToCode