Click to See Complete Forum and Search --> : Frame Waits For Another Frame Plz Help


choppedliver
08-05-2003, 11:59 AM
i have the following function

function loadFrames(frame1,page1,frame2,page2)
{
eval("parent." + frame1 + ".location='" + page1 + "'");
eval("parent." + frame2 + ".location='" + page2 + "'");
}


The problem is that frame 1 needs to finish loading before frame 2 should start loading. Otherwise, the data in the two frames may be inconsistent.

Any ideas?

goofball
08-05-2003, 01:27 PM
first, I think it would be easier to pass the frame into your function as an index number.

onClick="loadFrames(1,'menu.html',2,'main.html');"

That way you won't have to mess with eval.
The way I do this is to have the function written out in the top frameset (usually index.html)
In each page that is loaded by the frameset, a small javascript sets a variable that can read from the frameset.

<body onLoad="var loaded=1">


function loadFrames(f1,p1,f2,p2) {

var set;
if(set != 1) {
top.frames[f1].location = p1;
var set = 1;
}

if(top.frames[f1].loaded == 1) {
top.frames[f2].location = p2;
} else {
var args = f1 +',"'+ p1 +'",'+ f2 +',"'+ p2 +'"';
setTimeout("loadFrames("+ args +")",500);
}

}

choppedliver
08-05-2003, 02:49 PM
I like yoru answer. definitle more elegant. I did make a hack that works, but its not elegant.

I made an empty form called frmWait on frame1 at the bottom of the page. Since its JSP, by the time the page is being parsed the data i am worried about is already finished updating in the database.

I then checked for existence of the object like so

var a:
eval(.... frame1...)
while (!parent.frame1.frmWait)
a=a; //do nothing really, just a place holder.
eval(...frame2

that way i dont have to set a timer, it just waits till its created then immediately loads the other frame. Thanks for your help! I think i might give yours a try

goofball
08-06-2003, 07:48 AM
Right on! I like your hack, too. I don't know JSP, but it sounds similar to things I do in Perl. When the server-side app fills in some JavaScript code, I you don't have to call an onLoad or anything as long as the code gets filled in at the bottom of the page .... nice

But I just want to say that from my own experience with frames, you have to be carefull about checking objects in other frames with a script. Like if you call top.frames[1].document.object .... and the document hasn't loaded in the frame yet, you get an error and JavaScript stops running until the page is refreshed.

Your while() loop sounds better than my setTimeout() idea.
Thanks