這個給點參考。
--demo.html--
<HTML><HEAD><TITLE> New Document </TITLE>
<meta http-equiv="Content-Type"
content="text/html;charset=BIG5">
</HEAD><BODY>
<a href="Notepad">運行Notepad</a><br>
<a href="RunCmd">運行DOS</a><br>
</BODY>
</HTML>
-----------------------------
unit U_WebBrowser;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch
var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant
var Cancel: WordBool);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
str:String;
begin
str:=ExtractFilePath(Application.ExeName)+'demo.html';
Caption:=str;
WebBrowser1.Navigate(str);
end;
procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch
var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant
var Cancel: WordBool);
begin
if Pos('Notepad',URL)>0 then
WinExec('notepad.exe',SW_SHOWNORMAL)
else if Pos('RunCmd',URL)>0 then
WinExec('Cmd',SW_SHOWNORMAL)
else exit;
Cancel:=true;
end;
end.