Link to home
Start Free TrialLog in
Avatar of chongkeng_woon
chongkeng_woon

asked on

TWebBrowser OnDocumentComplete event

i have a problem in OnDocumentComplete event of TWebbrowser ...
a message will pop up after the whole document(including multiple frames) is finished loaded ..(see attached code) ......

however, i accidentally found that it is not 100% working for certain website
e.g.  http://www.chatterboxgifts.co.uk/x11506.html

it is continue loading to another page even though the message "Complete document was loaded" did pop up..

is there anyway i can make sure that the whole HTML page is 100% finished loaded regardless of how many frames, or how the page is contructed ?

thanks

procedure YourForm.OnDocumentComplete(
  Sender: TObject;
  const pDisp: IDispatch;
  var URL: OleVariant);
var
  currentBrowser: IWebBrowser;
  topBrowser: IWebBrowser;
  document: OleVariant;
  windowName: string;
begin
  currentBrowser := pDisp as IWebBrowser;
  topBrowser := (Sender as TWebBrowser).DefaultInterface;
  if currentBrowser = topBrowser then
    ShowMessage('Complete document was loaded')
  else
  begin
    document := currentBrowser.Document;
    windowName := document.ParentWindow.Name;
    ShowMessage(Format('Frame "%s" was loaded', [windowName]));
  end;
end;

Avatar of Greybird
Greybird

You should look in the help at the OnNavigateComplete2, OnDocumentComplete, example section.

It explains how to be sure that the page is fully loaded by using these 2 event handlers
Avatar of chongkeng_woon

ASKER

it did try ...but it doesn't work as well ...the given example in Help doesn't solve my problem ...
Strange, because I use this method very often, and it works really well for me...
it works to most of the webpage, almost 95% no problem ..(sorry if i misunderstanding you) ...
but, got exceptional case, can you try using TWebbrowser to navigate the following url:

http://www.chatterboxgifts.co.uk/x11506.html

this is the exceptional case i mentioned ..
Hello Sir,

 You could try some logic like this

var
  loadcomplete : boolean;

....
--eventcode
  loadcomplete := true
....
--your processingcode
  loadcomplete := false;
  --navigate-codinghere
  while not loadcomplete do sleep(100); //for example
  --process
  --back to start, in case of a loop

with regards,
padmaja.
Avatar of Eddie Shipman
It is happening because it is loading 5 FRAMES.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I will leave the following recommendation for this question in the Cleanup topic area:
- Delete (Refund)

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Pierre
EE Cleanup Volunteer
ASKER CERTIFIED SOLUTION
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial