Delphi Programming

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

How to check if a document in a TWebBrowser is located on a local drive

By Zarko Gajic, About.com

If you need to know the location of a document displayed in a TWebBrowser component, you need to get the Protocol property of the IHTMLLocation. Here's a function that returns true if a document in a WebBrowser is stored locally:

~~~~~~~~~~~~~~~~~~~~~~~~~
function WB_DocumentOnLocalDrive(wb: TWebBrowser): boolean;
const
   fileProtocol = 'file:';
var
   protocol : string;
begin
   if Assigned(wb.Document) then
     protocol := wb.Oleobject.Document.Location.Protocol;

   result := protocol = fileProtocol;
end;

Usage:
if WB_DocumentOnLocalDrive(WebBrowser1) then ShowMessage('Document on a local or network drive') ;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to allow column resize but disable movement (in TDBGrid)
« Adding About Delphi Programming site (link and the blog RSS feed) to the Delphi 2005 Welcome page

Explore Delphi Programming

More from About.com

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TWebBrowser
  6. How to check if a document in a TWebBrowser is located on a local (or network) drive

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

All rights reserved.