How to force a Download File prompt instead of displaying it in-browser with HTML?
This is something that you cannot absolutely control with HTML itself.
If the user is having a browser with PDF reading capabilities (or a plugin) and the corresponding settings to open PDF files in-browser, the PDF will open like that.
The PDF opens in a new tab simple because of your target="_blank"
, which has nothing to do with a download prompt.
If you are using HTML5 you can use the download attribute:
<a href="sample.pdf" download="sample.pdf">Download</a>
If you have a back-end service which you can control or you feel like fiddling with your Web Server, you can always look for setting the right Content-Disposition
. See this SO question for some nice discussion on Content-Disposition.
(HTML) Download a PDF file instead of opening them in browser when clicked
There is now the HTML 5 download
attribute that can handle this.
I agree, and think Sarim's answer is good (it probably should be the chosen answer if the OP ever returns). However, this answer is still the reliable way to handle it (as Yiğit Yener's answer points out and--oddly--people agree with). While the download attribute has gained support, it's still spotty:
http://caniuse.com/#feat=download
Related Topics
<Video> Plays in Other Browsers, But Not Safari
How to Center List Items Inside a Ul Element
Decode HTML Entities in Android
Xpath Testing That String Ends with Substring
Is It Ok to Use a Self Closing Div Tag
What Happens If the Meta Tags Are Present in the Document Body
Auto Height on Parent Container with Absolute/Fixed Children
Remove Background Arrow from Date Input in Google Chrome V20
Is the HTML Shown via 'View Source' Different from the HTML Shown in (Firebug) Developer Tools
Is There Any Benefit to Adding Accept-Charset="Utf-8" to HTML Forms, If the Page Is Already in Utf-8
HTML <Input Type='File'> Apply a Filter
Linking to CSS in an Svg Embedded by an Img Tag
Giving a Border to an HTML Table Row, <Tr>
Can <Span> Tags Have Any Type of Tags Inside Them
Bootstrap Right Column on Top on Mobile View
Why Does Chrome Incorrectly Determine Page Is in a Different Language and Offer to Translate