TWebBrowser 与 MSHTML(2): 获取 window 对象的时机

转自:万一博客

这是在页面下载完毕后即刻获取:

 

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.

 

此项目被张贴在未分类 。书签的 permalink

发表评论

电子邮件地址不会被公开。 必填项已用*标注