moonrisesystems
asked on
Javascript refresh in webbrowser control unintentionally fires FormActivate
Here's a strange one that has me stumped.
http://www.kioskremote.net/secure/files/display.asp?ZoneID=42
This is an ASP script for an advertising system that displays a set of defined "advertisements" in rotating fashion. The refreshes when the ad panel changes are done via a javascript refresh (load the link above into IE to see a demonstration).
Here's the problem. In a web browser control application, whenever I click on one of these ASP links and loaded the result into a new browser form(Unit2), Unit1's FormActivate event appears to fire everytime the javascript refresh command is called, forcing form2 to the background.
What is even stranger is this only happens when the ASP link is clicked. Normal links opened in form2 are unaffected.
Can anyone explain this weird behaviour?
In the sample application enclosed, the left browser on form1 is the ASP script that gives the trouble and the right browser on form1 is a normal plain HTML page. Form2 represents a pop up browser that opens as a result of clicking on one of the ad panels.
Here's the sample application with two units (unit1(main application), unit2(pop up browser)) to illustrate the problem:
------ unit1 -----
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, WebBrowser,Unit2, StdCtrls;
type
TForm1 = class(TForm)
NetStopBrowser: TWebBrowser;
NetStopBrowser3: TWebBrowser;
Memo: TMemo;
procedure FormShow(Sender: TObject);
procedure NetStopBrowserBeforeNaviga te2(Sender : TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
initial : Boolean;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
initial := True;
NetstopBrowser.Navigate('http://www.kioskremote.net/secure/files/display.asp?ZoneID=42') ;
initial := True;
NetstopBrowser3.Navigate(' http://www.google.com');
end;
procedure TForm1.NetStopBrowserBefor eNavigate2 (Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
begin
if initial then
initial := False
else begin
Cancel := True;
with TForm2.Create(nil) do begin
Show;
NetstopBrowser2.Navigate(U RL);
end;
end;
end;
procedure TForm1.FormActivate(Sender : TObject);
begin
memo.Lines.Add('form activated');
end;
end.
------------------
------ unit2 -----
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, WebBrowser;
type
TForm2 = class(TForm)
NetStopBrowser2: TWebBrowser;
procedure NetStopBrowser2BeforeNavig ate2(Sende r: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.NetStopBrowser2Befo reNavigate 2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
begin
showmessage(URL);
end;
end.
------------------
http://www.kioskremote.net/secure/files/display.asp?ZoneID=42
This is an ASP script for an advertising system that displays a set of defined "advertisements" in rotating fashion. The refreshes when the ad panel changes are done via a javascript refresh (load the link above into IE to see a demonstration).
Here's the problem. In a web browser control application, whenever I click on one of these ASP links and loaded the result into a new browser form(Unit2), Unit1's FormActivate event appears to fire everytime the javascript refresh command is called, forcing form2 to the background.
What is even stranger is this only happens when the ASP link is clicked. Normal links opened in form2 are unaffected.
Can anyone explain this weird behaviour?
In the sample application enclosed, the left browser on form1 is the ASP script that gives the trouble and the right browser on form1 is a normal plain HTML page. Form2 represents a pop up browser that opens as a result of clicking on one of the ad panels.
Here's the sample application with two units (unit1(main application), unit2(pop up browser)) to illustrate the problem:
------ unit1 -----
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, WebBrowser,Unit2, StdCtrls;
type
TForm1 = class(TForm)
NetStopBrowser: TWebBrowser;
NetStopBrowser3: TWebBrowser;
Memo: TMemo;
procedure FormShow(Sender: TObject);
procedure NetStopBrowserBeforeNaviga
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
initial : Boolean;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
initial := True;
NetstopBrowser.Navigate('http://www.kioskremote.net/secure/files/display.asp?ZoneID=42')
initial := True;
NetstopBrowser3.Navigate('
end;
procedure TForm1.NetStopBrowserBefor
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
begin
if initial then
initial := False
else begin
Cancel := True;
with TForm2.Create(nil) do begin
Show;
NetstopBrowser2.Navigate(U
end;
end;
end;
procedure TForm1.FormActivate(Sender
begin
memo.Lines.Add('form activated');
end;
end.
------------------
------ unit2 -----
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, WebBrowser;
type
TForm2 = class(TForm)
NetStopBrowser2: TWebBrowser;
procedure NetStopBrowser2BeforeNavig
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.NetStopBrowser2Befo
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
begin
showmessage(URL);
end;
end.
------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Closed, 500 points refunded.
Lunchy
Friendly Neighbourhood Community Support Moderator
Lunchy
Friendly Neighbourhood Community Support Moderator
instead of navigating to it there? I think that is the way to "redirect" a navigation to another browser.