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

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

By , About.com Guide

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
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  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

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

All rights reserved.