Richard2000
asked on
URL in OnNavigateComplete2 event is sometimes wrong with TWebBrowser
Hi,
I've noticed with some sites that the URL in OnNavigateComplete2 is sometimes wrong. To demonstrate, add a TWebBrowser object to the form along with this code...
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.OleObject.Navi gate('www.fish4jobs.co.uk');
end;
procedure TForm1.WebBrowser1Navigate Complete2( Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
Caption := URL;
end;
When it is run and the page has loaded, the Caption wrongly contains something like...
http://ads.fish4.co.uk/RealMedia/ads/adstream_sx.ads/www.fish4jobs.co.uk/hp/1018476186@x08
when in fact the actual URL should be...
http://jobs.fish4.co.uk/jobs/index.jsp
Why is this? I've noticed it happen with other sites too, such as the About.com sites. It seems to be most noticable with sites that serve ads. Do you know a work around to this problem? When I view the sites in IE itself, I never get this problem. I've tried EmbeddedWB, but it did not make any difference. I'm using Delphi 4 Pro.
Thanks in Advance,
Richard
I've noticed with some sites that the URL in OnNavigateComplete2 is sometimes wrong. To demonstrate, add a TWebBrowser object to the form along with this code...
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.OleObject.Navi
end;
procedure TForm1.WebBrowser1Navigate
const pDisp: IDispatch; var URL: OleVariant);
begin
Caption := URL;
end;
When it is run and the page has loaded, the Caption wrongly contains something like...
http://ads.fish4.co.uk/RealMedia/ads/adstream_sx.ads/www.fish4jobs.co.uk/hp/1018476186@x08
when in fact the actual URL should be...
http://jobs.fish4.co.uk/jobs/index.jsp
Why is this? I've noticed it happen with other sites too, such as the About.com sites. It seems to be most noticable with sites that serve ads. Do you know a work around to this problem? When I view the sites in IE itself, I never get this problem. I've tried EmbeddedWB, but it did not make any difference. I'm using Delphi 4 Pro.
Thanks in Advance,
Richard
listening
ASKER
Hi,
Thanks for the code. I've tried it, but I wonder if this method will sometimes prematurely get the URL? For example, when I tried it the URL displayed in the caption was...
www.fish4jobs.co.uk
but when I tried it in Internet Explorer the URL I got was...
jobs.fish4.co.uk/jobs/inde x.jsp
Are there any other ways?
Richard
Thanks for the code. I've tried it, but I wonder if this method will sometimes prematurely get the URL? For example, when I tried it the URL displayed in the caption was...
www.fish4jobs.co.uk
but when I tried it in Internet Explorer the URL I got was...
jobs.fish4.co.uk/jobs/inde
Are there any other ways?
Richard
ASKER
Hi,
I think the problem occurs because of the frames in the web page. Ads are often displayed in a separate frame, which is why it is most noticable with sites that display ads. I would like the URL displayed in the Caption to be the same as when the page is opened up in Internet Explorer itself. Is there any way of determining if the URL is a frame and ignore it?
Richard
I think the problem occurs because of the frames in the web page. Ads are often displayed in a separate frame, which is why it is most noticable with sites that display ads. I would like the URL displayed in the Caption to be the same as when the page is opened up in Internet Explorer itself. Is there any way of determining if the URL is a frame and ignore it?
Richard
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ and Refund
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Paul (pnh73)
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ and Refund
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Paul (pnh73)
EE Cleanup Volunteer
try this code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
procedure FormCreate(Sender: TObject);
procedure WebBrowser1DocumentComplet
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
StartNav : Boolean;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
StartNav := True;
WebBrowser1.Navigate('www.fish4jobs.co.uk');
end;
procedure TForm1.WebBrowser1Document
const pDisp: IDispatch; var URL: OleVariant);
begin
IF StartNav
then Caption := URL;
StartNav := False;
end;