這是在頁面下載完畢後即刻獲取:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses MSHtml;
var window: IHtmlWindow2;
{建立時同時打開頁面}
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Align := alTop;
WebBrowser1.Navigate('http://del.cnblogs.com');
end;
{當頁面打開完畢時獲取 window 對象}
procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
if pDisp = (ASender as TWebBrowser).Application then
begin
window := ((ASender as TWebBrowser).Document as IHtmlDocument2).parentWindow;
end;
end;
end.