TWebBrowser 与 MSHTML(2): 获取 window 对象的时机
作者:互联网
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.posted on 2009-03-13 17:20 万一 阅读(4466) 评论(7) 编辑 收藏
标签:end,TForm1,TObject,TWebBrowser,window,MSHTML,var 来源: https://blog.51cto.com/u_14617575/2745749