59

When I look at code samples on the web that are linked to as a .c, .cpp, .h etc file, chrome will download it for me as a file.

Is there a way to get it to open the file (which is really just a text file with a different extension, and chrome does open text files in a tab window) in a tab window?

I would rather not have my downloads folder littered with all of these small code files.

I have looked in the chrome preferences, but have not found anything that relates to this.

Running the dev build of chrome, but I would take the option in any current build of the browser.

EDIT: Is there a way to change the way that chrome handles some mime types like text/x-chdr or others?

soandos
  • 24,206
  • 28
  • 102
  • 134
  • Can you even edit Google Chrome's file associations? – iglvzx Mar 11 '12 at 18:25
  • 1
    Not sure what you mean. It generally uses my OSes file associations to open files with the correct extension... – soandos Mar 11 '12 at 18:29
  • You can manage file associations with Firefox's `Options > Applications` dialog. If Google Chrome had a comparable feature, you would have the choice to open the files in a new tab or another application directly. As far as I can tell, Google Chrome lacks such preferences. `:(` – iglvzx Mar 11 '12 at 18:34
  • Can you write an extension to do this? – conspiritech Mar 11 '12 at 18:51
  • Are you asking if I personally can, or if chrome supports it? – soandos Mar 11 '12 at 19:03
  • Does it happen with all source files from any site or just a specific site? – Synetech Mar 13 '12 at 19:19
  • 1
    Hmm, I just tried it myself. Opening a local `CPP` file (i.e., `file:///….cpp`) *does* open as text, only remote ones try to download. – Synetech Mar 14 '12 at 03:42
  • [\[1\]](http://groups.google.com/a/googleproductforums.com/forum/#!category-topic/chrome/discuss-chrome/mqbdHOu8hHM) [\[2\]](http://binfalse.de/2011/06/apache-displaying-instead-of-downloading/) – Synetech Mar 14 '12 at 04:11
  • 1
    possible duplicate of [How to open a C program file in browser window?](http://superuser.com/questions/136982/how-to-open-a-c-program-file-in-browser-window) – Synetech Mar 14 '12 at 04:12
  • In Opera, this would be under `Prefereces > Advanced > Downloads`, but I don't think there's anything comparable in Chrome. Are your OS file associations ignored if you set, say, `.cpp` files to be opened with Chrome? – Amos M. Carpenter Mar 14 '12 at 05:35
  • aaamos, I am using chrome, so not sure what you mean. @Synetech, that answer has 1) a faulty premise (no viewer required, default works just fine) 2) my issue is not related to Gmail (nor was the OP's in that question) I an just want to change the storage location to somewhere else (i.e. not my normal downloads folder, but a temp directory / just RAM or something, like other web pages). In short, don't think its a dupe – soandos Mar 14 '12 at 07:31
  • Actually it is. The point is that Chrome handles some file-types differently. – Synetech Mar 14 '12 at 18:04
  • Not an answer, but maybe pointing in a helpful direction: in Firefox this is possible via a browser extension called [Open in Browser](https://addons.mozilla.org/en-US/firefox/addon/open-in-browser/). Maybe Chrome could be likewise extended. – Robert Fleming Mar 15 '17 at 04:47

5 Answers5

22

I did a bunch of tests and found that some types always trigger a download from remote location. For example, .bat files always try to download while the similar .cmd type opens as text. Likewise, .cpp files always trigger a download while my own .inc type which is an identical copy of the .cpp with the “cpp” changed to “inc” opens as text.

I haven’t checked the source, but I suspect it’s a built-in behavior. They must figure that if it’s a local file (file:///…), you already have it so it is assumed to be trusted, so open it. If however it is a remote file, don’t open it, instead download it so that any anti-virus software on the system can have a look to be safe.

Surprisingly there do not seem to be any other complaints about this on the Chrome bug tracker. o.O I have submitted a report, so we’ll have to see what they say.

Synetech
  • 68,243
  • 36
  • 223
  • 356
  • Thanks. And also surprisingly only 10 users have upvoted (starred) it. +1 (me). – ChrisJJ Jan 10 '14 at 15:21
  • @ChrisJJ: That number is now up to 17, and I've added a comment with some thoughts about what the user interface should look like. – Keith Thompson May 22 '14 at 19:37
  • Thanks to Synetech for opening a ticket in the Chrome bug tracker, and helpfully providing the link. I've added my vote and a supportive comment. Have you? :-) – MykennaC Apr 09 '15 at 15:18
  • Tnx for issue, voted up! – menkow Mar 30 '16 at 08:31
  • https://bugs.chromium.org/p/chromium/issues/detail?id=118204&thanks=118204&ts=1331749873 It was closed automatically, I don't see how to reopen – Chiptus Apr 19 '21 at 08:59
3

Great question.

I can be achieved via an extension:

boardtc
  • 476
  • 4
  • 13
1

I used to use Syntaxtic! for Chrome, worked for me. It opens source code in a new tab and then applies syntax highlighting.

slhck
  • 223,558
  • 70
  • 607
  • 592
Xyzodiac
  • 11
  • 1
0

Google Chrome

Now its possible to open source code directly from browser. I tested on version 61.0.3163.91 64 bits.

Firefox

Here it isn't yet. To avoid this, do the following:

  1. Right-click on .c or other source code file;
  2. Copy link option
  3. Press CRTL-T to open new tab;
  4. Type "view-source:"
  5. Paste the link copied before.

Done! Firefox will show the source code of the file, in this case, the file itself.

-1

I was looking for the same question and found the answer from Danny B. at: https://stackoverflow.com/questions/14952514/how-to-force-open-links-in-chrome-not-download-them.

To make certain file types OPEN on your computer, instead of Chrome Downloading...

You have to download the file type once, then right after that download, look at the status bar at the bottom of the browser. Click the arrow next to that file and choose "always open files of this type". DONE.

Now the file type will always OPEN using your default program.

To reset this feature, go to Settings / Advance Settings and under the "Download.." section, there's a button to reset 'all' Auto Downloads

Did
  • 115
  • 1