用WebBrowser来做浏览器,但我怎样才可以判断网页是否加载完毕呢?(50分)

  • 主题发起人 主题发起人 陈桂坚
  • 开始时间 开始时间

陈桂坚

Unregistered / Unconfirmed
GUEST, unregistred user!
如题...................
 
自己关注一下....
这个问题真的好急好急的..请大家帮我看一下.....
 
是不是这个:OnDocumentComplete

procedure Tfrm_MainForm.wb1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
if (TWinControl(Sender).Parent) is TTabSheet then begin
TTabSheet(TWinControl(Sender).Parent).HelpKeyword := URL;
end;
cbex_Url.Text := URL;
Web_Gauge.Visible := False;

end;
 
应该不是这个啦..
 
if WebBrowser.ReadyState = READYSTATE_COMPLETE then
showmessage('文档完成');
 
就是OnDocumentComplete事件,看该事件的说明:
Write an OnDocumentComplete event handler to take specific action when a frame or document is fully loaded into the Web browser .For a document without frames, this event occurs once when the document finishes loading. On a document containing multiple frames, this event occurs once for each frame. When the multiple-frame document finishes loading, the Web browser fires the event one final time.

对于没有frame结构的页面,页面读取完毕会触发这个事件
对于有多个frame结构的页面,每个frame读取完毕都会触发这个事件,当所有frame都读取完毕后会触发最后整个页面读取完毕的事件,你可以使用该事件的URL来判断是否所有frame都读取完毕

用下面的程序来做测试,打开的是猫扑大杂烩的页面,典型的frame结构网页:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, ExtCtrls;

type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
const
TestURL:string='http://dzh.mop.com/mainFrame.jsp';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate(TestURL);
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
if url=TestURL then showmessage('网页打开完毕');
end;

end.
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw;

type
TForm1 = class(TForm)
wb1: TWebBrowser;
btn1: TButton;
procedure btn1Click(Sender: TObject);
procedure wb1DocumentComplete(Sender: TObject; const pDisp: IDispatch;
var URL: OleVariant);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
const
TestURL:string='http://et.21cn.com/'; //'最后的/是系统默认加的'

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
begin
WB1.Navigate(TestURL);
end;

procedure TForm1.wb1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
if url=TestURL then showmessage('网页打开完毕');
end;

end.
 
后退
顶部