Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

html - Opening files in browser instead of downloading

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...