方法一 Document 层
WebBrowser.Document:IDispatch
Var Doc: IHTMLDocument2;
begin
...
try As 时必须加try...except...end保护
Doc:= (WebBrowser1.Document) as IHTMLDocument2;
if Assigned(Doc) then begin //判断是否为空
...//具体操作
end;
except
...
end;
...
end;
方法二 Window 层
WebBrowser.QueryInterface(IID_IHTMLWindow2, Out Win: IHTMLWindow2);//返回WebBrowser控件的IHTMLWindow2接口
Var Win: IHTMLWindow2;
Begin
...
try
WebBrowser1.QueryInterface(IID_IHTMLWindow2, Win);
if Assigned(Win) then begin //判断是否为空
...//具体操作
end;
except
...
end;
...
end;