FirstpDisp : IDispatch;//全局变量;
ChkOpen, ChkOk : Boolean;//全局变量;
FirstpDisp := nil;//浏览URL之前赋nil;
procedure TForm1.FormCreate(Sender: TObject);
begin
ChkOpen := true;
ChkOk := false;
end;
procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
begin
if ChkOk and ChkOpen then
begin
ChkOk :=false;
ChkOpen :=false;
FirstpDisp := pDisp;
end;
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
ChkOk :=true;
if FirstpDisp = pDisp then
begin
//你要执行的任务
//
end;
end;