tags:

views:

39

answers:

1

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?

+4  A: 

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
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?
webdestroya
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
@webdestroya: Yes it should work as a link as well. `<a href="view-source:http://stackoverflow.com/questions/2831226/">Link</a>`
Daniel Vassallo
@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
@Daniel Vassallo - Oh cool, but that will only work in Chrome, not FF or IE
webdestroya
@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