[thelist] Javascript problem - trying to "wait"

Tom Dell'Aringa pixelmech at yahoo.com
Mon Jul 15 11:37:11 CDT 2002


Hi All,

I've got a tricky javascript issue. I have action B happening on page
load in an init() function. In order for B to happen, A must be
loaded first (to avoid a object required error). I have been
experimenting with setInterval() to accomplish this. I have the
problem KIND OF solved, but as our CAD developer said, its a bad
solution. Here is some code:

Function 1: Test to see if object has loaded
----------------------------------------------
function viewerTest()
{

if(parent.frames["graphicView"].document.getElementById("va_3d_vml_viewer"))
   {
      clearInterval(checkViewer);
      return true;
   }
   return false;
}
----------------------------------------------

So when this function is called it either returns TRUE or FALSE,
depending on if the viewer is there. makes sense. Here's the other
part, inside the init() function:

----------------------------------------------

// wait for viewer to be there

checkViewer = setInterval("viewerTest()", 50);

while(!viewerTest())
   {
      checkViewer;  //waiting for the viewer to continue.
   }
----------------------------------------------

Now, this seems to work, but here's the issue - its an overload on
server resources (which in the app I am working on is a BIG issue.)

I set the interval to the var checkViewer. This means the interval
starts checking the viewerTest() function every 50 milliseconds until
it finds it and is cleared there.

But, during my "wait" part in the while loop, I am ALSO checking
against viewerTest(), and during the while loop the check is CONSTANT
until it finds it. This is duplicating the process seemingly.

Lastly, I call the variable checkViewer (the interval) inside the
while loop. Why? If I don't, its an endless loop error. Crash. We've
tried merely using the while loop, checking against the viewerTest()
function. You would think that would work, but often we get an
endless loop crash.

This is a real stinker, any input is appreciated.

Tom



=====
var me = tom.pixelmech.webDeveloper();
http://www.pixelmech.com/

__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com



More information about the thelist mailing list