使用WEBBROWSER时网页跳转的问题 ( 积分: 200 )

  • 主题发起人 主题发起人 zcm1975117
  • 开始时间 开始时间
Z

zcm1975117

Unregistered / Unconfirmed
GUEST, unregistred user!
使用WEBBROWSER时,怎么在同一个窗口中打开弹出的网页窗口。
多谢指教。
 
使用WEBBROWSER时,怎么在同一个窗口中打开弹出的网页窗口。
多谢指教。
 
关键是DefaultInterface属性,如果设置Cancel为True,那么新网页就不会出来了

代码
unit Unit1;

interface

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

type
TForm1 = class(TForm)
WebBrowser2 : TWebBrowser;
WebBrowser1 : TWebBrowser;
Panel1 : TPanel;
procedure FormCreate(Sender: TObject);
procedure WebBrowser2NewWindow2(Sender: TObject; var ppDisp: IDispatch;
var Cancel: WordBool);
procedure WebBrowser1NewWindow2(Sender: TObject; var ppDisp: IDispatch;
var Cancel: WordBool);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser2.Navigate('http://www.163.com');
end;

procedure TForm1.WebBrowser2NewWindow2(Sender: TObject;
var ppDisp: IDispatch; var Cancel: WordBool);
begin
ppDisp := webbrowser1.DefaultInterface;
end;

procedure TForm1.WebBrowser1NewWindow2(Sender: TObject;
var ppDisp: IDispatch; var Cancel: WordBool);
begin
ppDisp := webbrowser2.DefaultInterface;
end;

end.


窗体文件
object Form1: TForm1
Left = 194
Top = 107
Width = 694
Height = 480
BorderIcons = [biSystemMenu, biMinimize]
Caption = '网页跳转示例'
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 12
object Panel1: TPanel
Left = 0
Top = 0
Width = 339
Height = 453
Align = alClient
Caption = 'Panel1'
TabOrder = 0
object WebBrowser2: TWebBrowser
Left = 1
Top = 1
Width = 337
Height = 451
Align = alClient
TabOrder = 0
OnNewWindow2 = WebBrowser2NewWindow2
ControlData = {
4C000000D42200009D2E00000000000000000000000000000000000000000000
000000004C000000000000000000000001000000E0D057007335CF11AE690800
2B2E126208000000000000004C0000000114020000000000C000000000000046
8000000000000000000000000000000000000000000000000000000000000000
00000000000000000100000000000000000000000000000000000000}
end
end
object Panel2: TPanel
Left = 339
Top = 0
Width = 347
Height = 453
Align = alRight
Caption = 'Panel2'
TabOrder = 1
object WebBrowser1: TWebBrowser
Left = 1
Top = 1
Width = 345
Height = 451
Align = alClient
TabOrder = 0
OnNewWindow2 = WebBrowser1NewWindow2
ControlData = {
4C000000A82300009D2E00000000000000000000000000000000000000000000
000000004C000000000000000000000001000000E0D057007335CF11AE690800
2B2E126208000000000000004C0000000114020000000000C000000000000046
8000000000000000000000000000000000000000000000000000000000000000
00000000000000000100000000000000000000000000000000000000}
end
end
end
 
多人接受答案了。
 
后退
顶部