你也可以这样:
procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
d:Variant;
begin
d:=WebBrowser1.Document;
Edit1.Text := WebBrowser1.OleObject.Document.title;
if((Edit1.Text='没有可以显示的页面') or (Edit1.Text='HTTP 404 未找到')) then
begin
d.Write('<b>出错了!</b>');
d.Close;
end;
end;
Private Sub object_NavigateError( _
ByVal pDisp As Object, _
ByVal URL As Variant, _
ByVal TargetFrameName As Variant, _
ByVal StatusCode As Variant, _
ByRef Cancel As Boolean)
Parameters
object
Object expression that resolves to the objects in the Applies To list.
pDisp
Object that evaluates to the top-level or frame WebBrowser object corresponding to the failed navigation.
URL
String expression that evaluates to the URL for which navigation failed.
TargetFrameName
String that evaluates to the name of the frame in which the resource is to be displayed, or Null if no named frame is targeted for the resource.
StatusCode
Integer that contains a status code corresponding to the error, if available. For a list of the possible status codes, see NavigateError Event Status Codes.
Cancel
Boolean that specifies whether to cancel the navigation to an error page and/or any further autosearch.
False
Default. Continue with navigation to an error page and/or autosearch.
True
Cancel navigation to an error page and/or autosearch.