21

Sometimes you want to follow a pdf/image/etc link and actually see it in the browser instead of downloading it.
In my most recent run-in it was with a screenshot on a Mantis server I'm using.

When I click to follow the link it immediately prompts me to save the file, with no option to open it the browser.
I really don't want to download it, open it in an image viewer, then remember to delete the file when I'm done. I'd like that to be handled by the browser when I close the tab for normal images/pdfs like when you click open [image] in new tab.

I know why the browser is doing it, the content is being served with the HTTP header Content-Disposition:attachment, but I'm sure that there would be an advanced setting, hidden context menu option, or awesome extension that would let you view something that somebody wanted you to actually save.

Does anyone know anything like that?


EDIT

Seems Firefox has an add-on for it, but I can't find a port for Chrome.

5
  • This is the source of the article: support.google.com/chrome/answer/1060734 Maybe you had Chrome PDF Viewer and Adobe Reader turned off by default?
    – Darius
    Sep 26, 2013 at 7:02
  • well this isn't just about pdf's, and I'm certain Content-Disposition overrides it (which is set by the server, not a user preference)
    – Hashbrown
    Sep 26, 2013 at 7:19
  • 3
    Just saw this.. and possibly a duplicate? --> superuser.com/questions/199382/… - (The answer refers to use a 'redirector' Chrome extension (chrome.google.com/webstore/detail/redirector/…) to remove content-disposition header.
    – Darius
    Sep 26, 2013 at 8:09
  • It's been answered here before stackoverflow.com/questions/6293893/…
    – Vasko
    May 3, 2016 at 0:56
  • @Vasko no it hasn't, those answers are all referring to what the webmaster can do to ensure users with their browsers download a file by default. My question is, as a user with no control over how the content is hosted, how do we enforce the opposite
    – Hashbrown
    May 3, 2016 at 8:27

4 Answers 4

5

Who defines whether the file will be downloaded or opened is the site developer. Naturally the file is opened in the browser, but if the developer force the HTML header below, will always be downloaded.

There is no way to force. :(

Response.AddHeader("Content-Disposition", "attachment; filename=fileToForceDownload.pdf");
Response.AddHeader("Content-Length", 12345);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytesOfFile);

To open in browser, developer must declare:

Response.AddHeader("Content-Disposition", "inline; filename=fileToOpen.pdf");
Response.ContentType = "application/pdf";

The above was written in C# but its parameters are common to any language sites

3
  • Issues with Android: stackoverflow.com/questions/4674737/…
    – Kiquenet
    Jan 25, 2017 at 15:46
  • Android 4, Ice Cream Sandwich. Example: Content-Disposition: attachment; filename="MyFileName.ZIP"; will not work correctly because of the semicolon at the end. Any tests (and summary) for all Android versions ? Useful: stackoverflow.com/questions/6319389/… Google Chrome v12 release introduced a bug that triggers the problem you describe. You can fix it by sending the Content-Length header bugs.chromium.org/p/chromium/issues/detail?id=85549
    – Kiquenet
    Jan 25, 2017 at 15:46
  • 1
    that's not true at all, even in my question I mention that there is a firefox addon that does work, and Darius had posted a comment that worked for chrome. The question specifically asks for a client solution and even alludes that the server-side correction is already known, but inapplicable in this case, so restating here doesn't help us. (I got an upvote for the question recently and I always go back and check on the answers if you're wondering why this comment came out of nowhere a few years later. I just wanted to let you know why you hadn't got the tick)
    – Hashbrown
    Aug 7, 2019 at 5:40
0

as said by Sergio it is the site developer who defines either the file will get downloaded or opened in browser. If you want to view pdf documents then I suggest to enable the Google Docs Extension which comes with chrome by default. Press the ctrl button while you click the image, it opens the image in new tab. I hope this works for users having this issue.

1
  • 1
    defines, sure, but we're looking for a workaround, which isn't impossible. ctrl+click would only work if the disposition isnt set to attachment, which was specified in the question. (this 'answer' would also have been better suited as a comment)
    – Hashbrown
    Aug 7, 2019 at 5:33
0

There's Modify Content-Type. It's working as I expected (PNGs open in the internal viewer despite Content-Disposition: attachment in the response headers) with a rule of:

URL Filter:       .*
Original Type:    application/png
Replacement Type: application/png
Disposition:      inline

Note well that this may expose you to cross-site scripting vulnerabilities, and you would be wise not to allow .* in the URL filter. Add to it only as needed.

Original answer

2
  • this looks perfect except that it doesnt work. Try this test, it always downloads. It should display like this. Tried with ., text/xml, text/xml, inline
    – Hashbrown
    Mar 11, 2021 at 5:45
  • This config worked for me: URL Filter: legacy\.legislation\.nsw\.gov\.au\/export\/xml\/regulation\/\d+\/\d+\?download=true Original Type: text/xml Replacement Type: text/xml Disposition: inline ```
    – across
    Mar 15, 2021 at 14:48
-1

Have you tried searching Google for "open PDF in Chrome"?

I had an extension that worked well:

Kami (formerly Notable PDF)
2.0.6344
Document Viewer and Office Tool for your browser

However, I disabled it because PDF will open in Chrome, even without that extension.

I do have:

Office Editing for Docs, Sheets & Slides
109.1486.1491
View and edit Microsoft Word, Excel, and PowerPoint files...

This allows me to open most Office files without having Office (look ma, no Office).

Hope this helps.

1
  • you want to follow a pdf/image/etc link, this question has nothing to do with pdf's specifically
    – Hashbrown
    Aug 7, 2019 at 5:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .