1. Home
  2. Computing & Technology
  3. Delphi Programming

How to call the View Source dialog in WebBrowser

By Zarko Gajic, About.com

Here's how to call a standard IE View Source dialog (to examine raw HTML) for the TWebBrowser component.

Usage: Simply drop an instance of TWebBrowser component on a form (and a Button) and call the find dialog as:

~~~~~~~~~~~~~~~~~~~~~~~~~
uses ActiveX;

procedure WBViewSourceDialog(AWebBrowser: TWebbrowser) ;
const
  CGID_WebBrowser: TGUID = '{ED016940-BD5B-11cf-BA4E-00C04FD70816}';
  HTMLID_VIEWSOURCE = 2;

var
  CmdTarget : IOleCommandTarget;
  vaIn, vaOut: OleVariant;
  PtrGUID: PGUID;
begin
  New(PtrGUID) ;
  PtrGUID^ := CGID_WebBrowser;
  if AWebBrowser.Document <> nil then
    try
      AWebBrowser.Document.QueryInterface(IOleCommandTarget, CmdTarget) ;
      if CmdTarget <> nil then
      try
        CmdTarget.Exec(PtrGUID, HTMLID_VIEWSOURCE, 0, vaIn, vaOut) ;
      finally
        CmdTarget._Release;
      end;
    except
   end;
  Dispose(PtrGUID) ;
end;

procedure TForm1.FormCreate(Sender: TObject) ;
begin
  WebBrowser1.Navigate('http://www.delphi.about.com') ;
end;

procedure TForm1.Button1Click(Sender: TObject) ;
begin
  WBViewSourceDialog(WebBrowser1) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
More Web Browser tips: TWebBrowser to the MAX

Delphi tips navigator:
» MORE TIPS
« Timeout MessageBox

Explore Delphi Programming

More from About.com

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TWebBrowser
  6. How to call the View Source dialog in WebBrowser

©2008 About.com, a part of The New York Times Company.

All rights reserved.