Solved

URL in OnNavigateComplete2 event is sometimes wrong with TWebBrowser

Posted on 2002-05-19
6
1,083 Views
Last Modified: 2012-08-14
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.Navigate('www.fish4jobs.co.uk');
end;

procedure TForm1.WebBrowser1NavigateComplete2(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
0
Comment
Question by:Richard2000
6 Comments
 
LVL 8

Expert Comment

by:Cesario
ID: 7020154
Dear Richard,

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 WebBrowser1DocumentComplete(Sender: TObject;
      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.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
  IF StartNav
    then Caption := URL;
  StartNav := False;

end;
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7020835
listening
0
 

Author Comment

by:Richard2000
ID: 7022408
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/index.jsp

Are there any other ways?

Richard
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:Richard2000
ID: 7029236
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
0
 

Accepted Solution

by:
Richard2000 earned 0 total points
ID: 7037465
Hi,

The solution I've created so far is this...

procedure TMain.WebBrowserNavigateComplete2(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
var
  Document: OleVariant;
begin
  if VarIsEmpty(WebBrowser.Document) then Exit;

  Document := WebBrowser.Document;

  if Document.Frames.Length = 0 then Caption := URL;
end;

This seems to work fine for virtually all sites.  The only site I had a problem with when testing is www.swreg.org.  Sometimes, the Caption isn't set (yet sometimes it is).  Anyone know why?

Richard
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9006022
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
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending Gmail through Delphi 3 102
delphi parse string to params 3 121
select query - oracle 16 100
Dynamically Created Query 3 54
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now