Programmatically open "View Source" HTML Window in Browser with Javascript?

Lance Pollard picture Lance Pollard · Nov 29, 2009 · Viewed 30.5k times · Source

How do I programmatically open the "View Source" window (using some Javascript) like when I right click in the browser and click "View Source"? Is this possible?

Answer

richardtallent picture richardtallent · Nov 29, 2009

You can use the "view-source" URI schema, supported by Firefox, Chrome, and older versions of IE.

No JavaScript required, just a normal link to the page you want the user to see in source view:

<a target="_blank" href="view-source:http://www.wikipedia.org/">view Wikipedia's home page HTML source</a>

More info:

http://en.wikipedia.org/wiki/View-source