/    Sign up×
Community /Pin to ProfileBookmark

Frame Waits For Another Frame Plz Help

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?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@goofballAug 05.2003 — 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">

[CODE]
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);
}

}
[/CODE]
Copy linkTweet thisAlerts:
@choppedliverauthorAug 05.2003 — 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
Copy linkTweet thisAlerts:
@goofballAug 06.2003 — 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
×

Success!

Help @choppedliver spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...