8 ms·
There are already ways to force browsers to download using HTTP headers. The author says this is a "server-side solutions to front-end problem", okay. But anyw
by jrochkind1 14y ago
There are already ways to force browsers to download using HTTP headers. The author says this is a "server-side solutions to front-end problem", okay.
But anyways, when pages use this already, it OFTEN pisses me off, when I want to look at a PDF in browser, but the web app/page is forcing me to save it to disk and then re-open it in another app.
What we _really_ need, that we _don't_ have a way to do right now -- is signal the browser to _prompt_ the user as to whether it should be saved or displayed in-browser. The browser could ignore unless it was capable of displaying in-browser of course. That's something we do not have any way of doing in a reliable way now with HTTP headers, and I wish html5 would add that, instead of duplicating a lesser feature which is both possible now, and frequently annoying.
- Poyeyo 14y agoI think Opera already does that.
- jrochkind1 14y agoRight, some browsers do, some don't. (I used to be able to _get_ Firefox to, with the right config, but stopped being abel to figure out how, then switched to chrome where i haven't figured out how either). But what we need is a standard cross-browser way to request this behavior (prompt for download vs show), that by default standards-compliant browsers will comply with (I'll allow for users over-riding this default behavior with configuration, if the browser wants to support that, sure). We don't have that. I wish html5 would add that, instead of minorly improving an annoying thing we already have (way to signal the browser to force or default to download). Sure, it should be avail in the HTML not just in HTTP headers, so the browser can let the signal effect it's UI before it does an http request for the asset, sure.
- anonymfus 14y ago>But what we need is a standard cross-browser way to request this behavior (prompt for download vs show), that by default standards-compliant browsers will comply with (I'll allow for users over-riding this default behavior with configuration, if the browser wants to support that, sure). It would be annoying too. If I want to open bunch of such links as background tabs then I would need to temporally change this setting and don't forget to return it. From usability standpoint (ignoring security and performance considerations) it's better to show me content and save button simultaneously. Then why do it only when site author wants it? Saving images is common operation and it would be better to show save button for every non-dynamic content. Why modern browsers don't have save button (https://upload.wikimedia.org/wikipedia/en/0/0f/Opera_3.62.png https://upload.wikimedia.org/wikipedia/en/0/0f/Opera_3.62.pn... ) on toolbar by default and want users to use menus for such common operation? Because designers don't have a place to put it without reducing usability for most common scenarios of browser use. Also save button was not replacement for "Save as" in context menu. Do we have solution for situation when application is complex enough that there is bunch of operations which are used rarely but must be easily accessible in one click and could be context-dependant? Yes. Microsoft's Ribbon.
- Sami_Lehtinen 14y agoI really would love if Dolphin Browser and Opera Mini would open PDF files in browser. Downloading files for viewing and opening PDF reader really isn't nice option, when you simply want to have a quick look what the file is really about. Google's quick view has saved me many times. But there really should be one simple and good solution for this problem.
- hpaavola 14y agoYeah, isn't "Content-Disposition: attachment;" header exactly for this?
- jsingleton 14y agoContent-Disposition can be very useful but it does have some potential security implications: http://www.gnucitizen.org/blog/content-disposition-hacking/ http://www.gnucitizen.org/blog/content-disposition-hacking/
- Xylakant 14y agoThe security implication in this case is not directly related to content-disposition. It could just as well be implemented using the download attribute. The gist of the attack is that it was possible to inject arbitrary javascript into an html file that was downloaded. After opening the file locally, the usual browser protections do not apply since it's a local file and the javascript can use this to escalate its privileges.
- porges 14y agoThis way lets you do it for files hosted somewhere you don't have control of.
- zokier 14y agoOpen in browser extension for Firefox might be somewhat close to what you'd want. https://addons.mozilla.org/en-us/firefox/addon/open-in-browser/ https://addons.mozilla.org/en-us/firefox/addon/open-in-brows...
- raverbashing 14y agoWhich is funny, because I absolutely loathe opening in the browser, I prefer saving it. Chrome and FF PDF viewers are better, but with Acrobat it was a bag of hurt. Also, see: saving is the more generic answer. Save and you can see it, open it and before the Chrome 'save' button you had to re-download it.
- deleted 14y ago[deleted]
- jrochkind1 14y agoIf Chrome didn't offer any way to 'save as' a PDF that it was displaying (really?!?), that's clearly Chrome's problem.
- alxeder 14y agothere are at least 3 ways to save an opened pdf with chromes viewer.
- FuzzyDunlop 14y agoUnless it comes from one of a number of journal or research sites, where at least one of those options will no longer work.
- coreyja 14y agoThat's cause you aren't actually looking at a PDF, most likely. If you are actually looking at a PDF in Chrome's renderer you will definitely be able to save it.
- TillE 14y agoOn Windows I've yet to see any PDF viewer that's faster or better than Sumatra. All the in-browser ones are a bit slow and lacking in features.
- 14y ago
- tripzilch 14y ago> when I want to look at a PDF in browser does that ever happen? > but the web app/page is forcing me to save it to disk and then re-open it in another app. because SumatraPDF actually loads faster than Adobe's browser plugin. Plus it's more secure, lacking all the weird scripting crud that shouldn't be in a document format anyway, smaller and open source. Only downside is that it can be really, really, really yellow.
- drivebyacct2 14y agoAdobe? Ha. I'll take Chrome or Pdf.js in Firefox, both of which are as fast or faster than the also fast Sumatra.
- bjhoops1 14y ago>> when I want to look at a PDF in browser > does that ever happen? I do this all the time. I hate downloading crap that I'm probably just going to glance at once then discard.
- tripzilch 14y agoOK yes I understand better now. I never realized that other browsers apparently don't offer the "open with default application" option in the download dialog, like Opera does. And actually quite some other applications do this (open as a temporary file) as well, it's a very common pattern: 7-Zip, FileZilla, to name a few. And even if you didn't, there's always a temp directory that gets cleaned next reboot. Though I agree, the browser should take care of this, like most apps.
- dspeyer 14y agoDefault application, yes. A browser tab, no. When I just want to look at an image, firefox is largely preferable to gimp. When I have a bunch of pdfs, firefox tabs are easier to manage than evince windows.
- steveklabnik 14y ago> does that ever happen? Yes, I do this all the time. I read a _lot_, and I often don't want to save the file on my hard drive unless I'm going to refer to it again in the future. And if I do, I can just choose "Save" at that point.
- jcampbell1 14y agoContent-Disposition attachement is one of the hardest things to implement when you have UTF-8 filenames. You have to browser sniff, and even then I have haven't found a good solution. Does anyone know of a good resource that explains all the edge cases that must be handled?
- d0mine 14y agoHere's some browser testing http://greenbytes.de/tech/tc2231/ http://greenbytes.de/tech/tc2231/ The link is from http://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http http://stackoverflow.com/questions/93551/how-to-encode-the-f...
- kijin 14y agoSee [1] for a very comprehensive and up-to-date table of browser support for various encoding schemes. See [2] for browser-specific hacks. Summary: most modern browsers including IE9 support RFC2231/5987. (Edit: see my other comment in this thread for IE6-8.) Another option is to leave out the troublesome "filename" parameter altogether and use the last part of the URL to convey the same information, e.g. /files/uploads/2013/<file_id>/filename.ext. After all, most browsers already understand how percent-encoding works in the URL. With today's URL rewriting engines, this shouldn't be too difficult to achieve regardless of how your files are actually organized on disk or which language you use to perform access control. It would be as if the client were requesting a static file. [1] http://greenbytes.de/tech/tc2231/ http://greenbytes.de/tech/tc2231/ [2] http://stackoverflow.com/questions/7967079/special-characters-in-content-disposition-filename http://stackoverflow.com/questions/7967079/special-character...
- jcampbell1 14y agoThanks. These days it looks like a reasonable solution is to just call the file "download.ext" for anything older than IE9. When I was trying to implement a solution to this problem years ago, what I thought would take 20 minutes of coding, started to look like a week of research and testing, and I gave up.
- driverdan 14y agoMobile Chrome often gets this correct. For many file types it will ask what you want to do if you haven't set a default action. Just never set a default and it always asks.
- marcosdumay 14y agoIsn't that exactly what browsers ask you when you click in "Save as"? Ok, it's not "display in browser", it's just "display" (or "open"), but what's the difference?
- dspeyer 14y agoGenerally the "open" option opens in some other app, not the browser. Including for formats the browser actually displays better.
- thomasluce 14y agoI don't think that it is a "server-side solution to a front-end problem". I believe that the right-click/save-as pattern was a front-end solution to a server-side problem. The problem is developers not knowing how to properly set their content type and disposition headers.
- Aardwolf 14y agoI would love to have an option in the right click menu to IGNORE the HTTP headers. For example, sometimes there is a link to an image like a jpg or a png that then forces you to download it. It REFUSES to ever render it in your browser. A right click option to ignore all MIME types and show it based on extention or magic bytes in the file would be AWESOME. Why do no browsers have that?
- chocolateboy 14y agoAs mentioned below, this is available in Firefox: http://spasche.net/openinbrowser/ http://spasche.net/openinbrowser/
- andrethegiant 14y agoI like the current method in Safari that opens PDFs in browser by default, but if I wast to save the PDF to disk, I just Option-click.
- timrogers 14y agoAgreed. Depending on context (of the content and myself!), sometimes I'll want to save and sometimes not. A prompt from the browser would be the best option, but alternatively, I'd want the site to offer me an option as to how the external file should be handled. If the browser doesn't implement it, it says that the "Right click to save" nonsense could make sense.
- wwweston 14y agoThat's a pretty good idea -- perhaps a "prompt" attribute instead of a "download" attribute. Lends itself reasonably well to a JS-only implementation, too: http://jsfiddle.net/FLa8P/1/
- jakerocheleau 14y agoAwesome fiddle! Thanks for sharing that here, it's definitely a unique solution.
- jrochkind1 14y agoNice, that JS is a great idea, thanks. And of course it relies on the download attribute. So, okay, I guess the `download` attribute DOES make this possible with a bit of JS, where it wasn't before, okay, one step forward. One nice feature of your solution is the user can still skip the prompt with a right-click or modifier-click 'save as' or 'open in new tab'. Nicely done. I'm gonna use that in the future. To be more strictly legal, I'd use a `data-prompt="true"` attribute or something, instead of a not entirely legal made up 'prompt' attribute.
- tomrod 14y ago> What we _really_ need, that we _don't_ have a way to do right now -- is signal the browser to _prompt_ the user as to whether it should be saved or displayed in-browser Like "right-click and save-as"? I personally don't mind the small choice I get to make when downloading a file.
- mcgwiz 14y agoGood point, but such a prompt would be similarly annoying (i.e. annoying to a similar number of users). The way I've done this in the past has been to provide two links, one of which triggered the inclusion of HTTP headers at the server, to trigger the Save dialo). Assuming the download attribute is supported, it's even easier: <a href="file.txt">File</a> (<a href="file.txt" download>Download</a>) This could impact visual design in a negative way. A download icon[1] could be used instead. <a href="file.txt">File</a> <a href="file.txt" download class="download-icon" title="Download this file">Download this file</a> CSS would be used render an icon and to make the text of .download-icon conveyable only in non-graphical browsers. [1] http://fortawesome.github.io/Font-Awesome/#icon/icon-download-alt http://fortawesome.github.io/Font-Awesome/#icon/icon-downloa...
- malandrew 14y agoThe option approach with the ability to set a default is the best approach. Then depending on the default, the right click will show the non-default option.
- vickytnz 14y agoI moved to Chrome just to be able to see PDFs in browser. Lots of websites have info that way (restaurants are the worst) and I don't want to get it saved on my computer just to have to delete it!