0

I'm creating a web page with a link to a PDF file.

I have been asked to set up the link so that the user can click the link once and see the PDF. Here's what I've tried so far:

One way is to simply put <a href="XXX.pdf" target="_self">PDF</a> in the HTML

The other is to make the link trigger Javascript: window.open("XXX.pdf", "_self");

Either way, IE always shows a prompt that says, "Do you want to open or save XXX.pdf", so that the user must click again to open the file. I get similar results in both Chrome and Firefox.

I have been asked to set up the web site so that the user can open the PDF with one click. How can I do this? I suspect that maybe I need to set the response headers on the web server a certain way. My web stack is ASP.net

Vivian River
  • 31,198
  • 62
  • 198
  • 313

2 Answers2

0

Okay, I found the solution. I feel silly saying this, but it turns out that my server was programmed to send a header specifying that the browser should download the file and give it a specific name. Once I took that out, everything worked fine. IE is able to open the PDF in the same tab, or a new tab, just like any other content.

In short, I just needed to get rid of:

result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
    FileName = $"my_file.pdf"
};
Vivian River
  • 31,198
  • 62
  • 198
  • 313
-2

Couple of interesting links:

User side: https://helpx.adobe.com/acrobat/using/display-pdf-in-browser.html

PHP: How do I force files to open in the browser instead of downloading (PDF)?

ASP: http://dotnetcode143.blogspot.in/2012/05/open-pdf-file-in-new-browser-tab-using.html

HTML: Some links are saying to set the target to "_blank"

Marker
  • 560
  • 4
  • 20
  • Thanks for these links, but none of the linked solutions worked for me. I get the same old "Do you want to open or save" prompt. – Vivian River May 10 '18 at 21:34