Check child window finished loading (without using onLoad ???)

Hi,

   I'm trying to figure out how to verify that a spawned window has finished laoding.
However, I am not writing the page that gets loaded into the child window so I can't just use the onLoad event on that page to trigger something in my window (at least I don't think I can can I ???). The client page is on another domain but I am a trusted client so can access the DOM so I thought that maybe there might be a way to wait for the closing hmtl or body tag ? But I haven't found a way of doing it...
Can anyone help me ??? Thanks,

   Drewbert
drewbert78Asked:
Who is Participating?
 
[ fanpages ]IT Services ConsultantCommented:
Hi,

The child window could set the value of a variable to a pre-defined setting that could be queried by the parent in a Timer-based loop.  As soon as the value is set as expected then the parent can cease the reinvocation of the Timer and continue as desired.

I have used a similar technique with frame-based windows.

Each .htm in the frames incremented a counter initialized in the Parent and the Parent checked for a value equal to the number of frames expected to load.  For example, 5 frames were defined, and in the Body "OnLoad" event of each of the pages in the frames was code to increment the counter Parent.intFrame_Loaded.  The Parent looped on a Timer event waiting until the intFrame_Loaded variable was set to 5.

Would that approach help?

BFN,

fp.
0
 
[ fanpages ]IT Services ConsultantCommented:
Hi,

Do you have any control about the contents of the source in the spawned window of the other party's code, or do you need a solution that could be applied to any spawned page?

i.e. could you request changes to the third party code, or is this not feasible?

Thanks for your clarification.

BFN,

fp.
0
 
drewbert78Author Commented:

Hi,

   well, both really - unfortunately I have no control over the page in question, plus I would like to come up with a generic solution...

   I've found that I acn query "window.document.readyState" which will return the state of the document as "complete" when it's finished loading. However, I haven't found a way of suspending execution in the parent window while polling the child (e.g. every second) until this is set as setTimeout returns before calling itself again so the parent would carry on with it's code. Thus I guess the problem has evolved into the original question, plus "Can I write my own javascript event and event handler so I can fire the event from the funciton polling the child window ?" or "Is there another way to suspend execution indefinitely until some condition is met ?". This might be better explained with some pseudo-code :-

function a()
{
  openChildWindow();
  waitForChildToLoad();

  doOtherSTuff();
}

funciton waitFortWindowToLoad()
{
  if (childWindow.document.readyState != complete) setTimeout(waitForChildToLoad, 1000);
  else return true;
}

The above will return and call doOtherSTuff() straight away irrespective of whether the child has loaded or not... All help greatfully appreciated - hence another 50 points...

  Drewbert
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
[ fanpages ]IT Services ConsultantCommented:
Hello.

Do you need any further assistance?

Thank you for your reply in any respect.

BFN,

fp.
0
 
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: fanpages {http:#9934280}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0
 
drewbert78Author Commented:

   As I stated, I don't actually have control of the client window so setting a variable in the client on the client side is not an option...

   Having done a lot of digging however, I did find that there exists, in the DOM, an attribute window.document.readyState which will be set to "complete" when the window has finished loading. This does however require access to the client DOM which is not allowable cross-domain... Not to be put off by this, I carried on digging and have found a way to gain access to the client DOM by being a trusted client so I can now simply poll the readyState of the client window while it is loading...
0
 
[ fanpages ]IT Services ConsultantCommented:
Hi again,

Glad you found a solution.

Does this mean that you are now in a position to close this question?

Thanks for your further feedback/comments.

BFN,

fp.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.