SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Automating View Source
By Scott Isaacs

Both Netscape Navigator 3/4 and Internet Explorer 4.0 support a convenient protocol for quickly displaying the source code of a document: view-source. The view-source protocol automates the command for displaying the source code in a separate window. This is very useful when creating pages where you want to let the user review your code. The view-source protocol works as follows:

  view-source:Absolute URL to page

The absolute URL must be a complete http:// or file:// address. For example to view the source code for this page the entire path is required:

  view-source:http://www.insideDHTML.com/tips/html/ts03/page1.asp"

You can use this protocol in a link creating a convenient way to display any pages source code:

  <A HREF="view-source:http://www.insideDHTML.com/tips/html/ts03/page1.asp">
    View this page's source
  </A>

View this page's source

You cannot target the output of the view-source to specific frame or window. Instead, the browser automatically displays the specified document in the default editing environment for the browser (eg., notepad for IE4, a new browser window in Netscape).

Discuss and Rate this Article