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?

  • 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
  • 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 3:42
  • 1
    possible duplicate of How to open a C program file in browser window? – Synetech Mar 14 '12 at 4:12

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.

  • 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 9 '15 at 15:18
  • Tnx for issue, voted up! – menkow Mar 30 '16 at 8:31
  • bugs.chromium.org/p/chromium/issues/… It was closed automatically, I don't see how to reopen – Chiptus Apr 19 at 8:59

Great question.

I can be achieved via an extension:


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

  • 1
    Does not work for me. How do you use it? – soandos Mar 14 '12 at 2:39
  • I installed Syntaxtic!, but CPP files still open a Save As dialog instead of in a tab as plain-text. – Synetech Mar 14 '12 at 3:42

Google Chrome

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


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.


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

  • 12
    I wanted this to open in a chrome tab, not the system text editor – soandos Dec 8 '16 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.