6

I want to open a file in a web browser (anyone will do) and I want to see it in the view source mode instead of in the standard browser window. This can be done in two steps, by opening the file and then go to the view source window (different shortcuts in each browser), but I want to directly go to the view source window. I have not found any such command line argument for Firefox nor Chrome.

Is this possible just with the base browser functionality?

JorgeLarre
  • 103
  • 1
  • 5
  • 1
    Why not just open in a text editor/viewer application of your chosing? Essentially its the same thing. – Matt May 14 '10 at 01:05
  • @Yoda Not if you want to see the 'rendered' html output of a cgi script. – Jamie Nov 24 '14 at 18:22

1 Answers1

7

In Chrome and Firefox you can use the view-source URI scheme by prefixing your URLs with view-source: as in the following example:

view-source:http://stackoverflow.com/questions/2831226/
Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443
  • I'm not sure if you can launch a browser and have it load that. I know you can load that once you are in the browser, but not by clicking a link? – Mitch Dempsey May 14 '10 at 01:10
  • Thanks, Daniel. It worked well in Chrome (it opens the file in View source mode), it did not work in Firefox 3.5.9 nor in Internet Explorer 7. One follow up question: is there a way to jump to a line number, instead of just opening the file at the first line? – JorgeLarre May 14 '10 at 01:23
  • @webdestroya: Yes it should work as a link as well. `Link` – Daniel Vassallo May 14 '10 at 01:39
  • @JorgeLarre: I think in Firefox for Windows it has been disabled, but you can enable it with [an extension](https://addons.mozilla.org/de/firefox/addon/2070/). However, I do not think there is the capability to jump to a particular line number. – Daniel Vassallo May 14 '10 at 01:41
  • @Daniel Vassallo - Oh cool, but that will only work in Chrome, not FF or IE – Mitch Dempsey May 14 '10 at 01:41
  • @webdestroya: There's more info on the browser compatibility in the wikipedia page: http://en.wikipedia.org/wiki/View-source_URI_scheme. It works on my Firefox 3.6.3 for Mac, but I think it has been disabled on Windows. – Daniel Vassallo May 14 '10 at 01:43
  • I am using Firefox 92 on Windows 10 and the view-source URI is working. However, FF seems to have issues viewing large source code this way (I can show some 250000 lines in Chrome but FF keeps loading endlessly) – mihca Oct 07 '21 at 12:12