How To Show Web Page Source from a Hyperlink (188762)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.5

This article was previously published under Q188762

SUMMARY

This article describes how to create a hyperlink on a Web page that shows the source code for the current page or another page when the hyperlink is selected.

MORE INFORMATION

Using an anchor tag with its associated HREF parameter, you can cause a hyperlink to display the source of a Web page when the hyperlink is clicked. To do so, set the value of the HREF parameter equal to "view- source:someFile.htm" where someFile.htm is the name of an HTML file that you want to show using the default editor for HTML source code.

Being able to display the source code of a Web page is valuable to those Internet Content Providers (ICPs) that wish to demonstrate how their pages have been created.

Please note that "view-source" works only on absolute links. Also, if you are trying to access an HTML file through the FILE protocol, you must fully qualify the URL like this:

Some Link

The following HTML code demonstrates how to show the source code for http://www.microsoft.com/ie40.htm when the hyperlink is pressed.
   <HTML>
      <HEAD>
         <TITLE>Show microsoft.com source code</TITLE>
      </HEAD>
      <BODY>
         <A HREF="view-source:http://www.microsoft.com/ie40.htm">
            Show microsoft.com/ie40.htm source code
         </A>
      </BODY>
   </HTML>
				
NOTE: When you use this protocol a copy of the file is written to the temp directory.

REFERENCES

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbDHTML kbhowto kbHTMLObj kbieObj KB188762