如何给TWebBrowser增加NavigateError事件

zwjchina 2005-07-17 05:01:09
如何给TWebBrowser增加NavigateError事件
...全文
478 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jbas 2005-07-17
  • 打赏
  • 举报
回复
你也可以这样:
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;
TechnoFantasy 2005-07-17
  • 打赏
  • 举报
回复
不过我记得NavigateError事件只有IE 6才支持,所以如果你的机器上面装的是IE6以下的版本的话,即使是重新导入了Microsoft Internet Controls也是没有OnNavigateError事件的。
TechnoFantasy 2005-07-17
  • 打赏
  • 举报
回复
你重新安装Webbrowser控件就可以了。方法是删除原来安装的TWebbrowser控件,然后选择菜单:Component | Install ActiveX Control。然后在里面选择Microsoft Internet Controls。新安装的
TWebbrowser会带OnNavigateError事件的。
zwjchina 2005-07-17
  • 打赏
  • 举报
回复
但是我不知道如何在Delphi7的TWebBrowser中加入这个事件。。。
高手帮帮忙。。。。。。。
zwjchina 2005-07-17
  • 打赏
  • 举报
回复
但是我不知道如果在Delphi7的TWebBrowser中加入这个事件。。。
高手帮帮忙。。。。。。。
zwjchina 2005-07-17
  • 打赏
  • 举报
回复
MSDN中的一段:
NavigateError Event

--------------------------------------------------------------------------------

Fires when an error occurs during navigation.

Syntax

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.

hthunter 2005-07-17
  • 打赏
  • 举报
回复
出错时,会自动转到显示本地的出错页面。你可以检测这些变化并相应的重设webbrowser的内容。

可能出错时也会相应的系统消息处理,不过没有研究过,呵呵
hthunter 2005-07-17
  • 打赏
  • 举报
回复
何谓NavigateError?找不到网页或者域名无法解释等?

5,515

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧