The World’s Leading Microsoft .NET Magazine
   
 
timstall

Donate Today!

Search Box

 

Calendar

««Mar 2010»»
SMTWTFS
  12
3
456
7
8
9
10
111213
1415161718
19
20
21222324252627
28293031

My RSS Feeds








Mailing List

Most Popular Tags

                                                           

Viewing the source of an Html File, even with the ContextMenu disabled

posted Wednesday, 29 March 2006

In IE, you can view the source of any file through either the context menu or tool bar. However, sometimes there are design reasons to disable or hide these. For example, you can prevent the content menu by putting this in the a script in the HTML body:

document.oncontextmenu=new Function("return false");

And you can hide toolbars by opening up a new window and passing in the appropriate options:

window.open(...);

However, even if a site does this, you can still view the source through the VS.Net debugger. Simply start debugging one of your own apps, then navigate to the target site in the address bar, and you'll see full source in the Script Explorer window.

tags:    

links: digg this    technorati    




1. Jeff Parker left...
Thursday, 30 March 2006 8:29 am

Well you can do a lot of other things as well. 1) Grab the file from cache. It is downloaded and written there, it may expire quickly but it is still there. 2) Write yourself a handy little .net control to do it. In the 2.0 framework the web browse control can be used to navigate to any url and you can rip the source completely from there. 3) There are some older API's into IE where you can have an external program control IE and rip through the DOM of downloaded page. I do not remember all of them exactly but by using PInvoke on these older API's there is one that just gives you the actual document as text. Sorry I can't remember the API's exactly I would have to dig back through some very old vb 6 code.


2. Tim Stall left...
Monday, 3 April 2006 9:00 am

Hey Jeff, nice suggestions. Thanks!


3. JenniC left...
Thursday, 24 September 2009 10:25 am

The following biterscripting commands will also show you the HTML source.

cat "http://www.somedomain.com/somepage.html"

The above will show you HTML source.

script "C:/Scripts/SS_WebPageToText.txt" page("http://www.somedomain.com/somepage.html")

The above command will show you the plain text (without HTML tags) of the same page.

These commands can be downloaded free at http://www.biterscripting.com . It's a good tool to have.

Jenni