javascriptview-source

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


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?


Solution

  • 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