1. Computing & Technology

Discuss in my forum

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

©2012 About.com. All rights reserved.

A part of The New York Times Company.