Solved

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

Posted on 2003-12-10
9
661 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:drewbert78
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
9 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 9912508
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
 

Author Comment

by:drewbert78
ID: 9918888

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
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 175 total points
ID: 9934280
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10102528
Hello.

Do you need any further assistance?

Thank you for your reply in any respect.

BFN,

fp.
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10395228
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
 

Author Comment

by:drewbert78
ID: 10400639

   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
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10400693
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

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 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