Solved

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

Posted on 2003-12-10
9
657 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
  • 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

746 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

9 Experts available now in Live!

Get 1:1 Help Now