如果是用新窗体打开,而不是用IE打开,简单一点:(From MSDN)
01 |
procedure TForm1 . WebBrowser1NewWindow2(Sender: TObject; |
02 |
var ppDisp: IDispatch; var Cancel: WordBool); |
06 |
frmWB := TForm1 . Create(Application); |
08 |
frmWB . WebBrowser1 . RegisterAsBrowser := TRUE ; |
09 |
ppDisp := frmWB . WebBrowser1 . OleObject; |
10 |
frmWB . Visible := TRUE ; |
如果是用当前WebBrowser打开,可以这样:(为描述清楚,列出了我的整个单元)
06 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
07 |
Dialogs, OleCtrls, SHDocVw, StdCtrls; |
10 |
TForm1 = class (TForm) Button1: TButton; WebBrowser1: TWebBrowser; procedure Button1Click(Sender: TObject); procedure WebBrowser1NewWindow2(Sender: TObject; var ppDisp: IDispatch; var Cancel: WordBool); procedure tempWBBeforeNavigate2(Sender: TObject; const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData, Headers: OleVariant; var Cancel: WordBool); procedure WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); |
24 |
procedure TForm1 . Button1Click(Sender: TObject); |
26 |
Self . WebBrowser1 . Navigate('http: |
29 |
procedure TForm1 . WebBrowser1NewWindow2(Sender: TObject; |
30 |
var ppDisp: IDispatch; var Cancel: WordBool); |
32 |
if not Assigned(tempWB) then tempWB := TWebBrowser . Create(Self); |
33 |
tempWB . OnBeforeNavigate2 := Self . tempWBBeforeNavigate2; |
34 |
ppDisp := tempWB . OleObject; |
37 |
procedure TForm1 . tempWBBeforeNavigate2(Sender: TObject; |
38 |
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData, |
39 |
Headers: OleVariant; var Cancel: WordBool); |
41 |
Self . WebBrowser1 . Navigate(Url); |
45 |
procedure TForm1 . WebBrowser1DocumentComplete(Sender: TObject; |
46 |
const pDisp: IDispatch; var URL: OleVariant); |
48 |
if Assigned(tempWB) then FreeAndNil(tempWB); |