Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting page loading completion

Status
Not open for further replies.

forrozeiro

Programmer
Sep 1, 2001
38
0
0
BR
Hi there,

Is there a way I can detect when a frame has finished loading a page?
I have a link in a frame that calls a function which loads a page in another frame. Like this:

function loadPage( url, target )
{
target.location.href = url;
if( loadingFinished( /* params ? */ ) )
{
//do stuff
}
}

I'm looking for a implementation for the loadingFinished() function.

Thank you in advance.
 
if i understand you correctly you want to run the code inside the

if(loadingFinished){
}

when the page in the frame loads?

well id make this a seperate function and call it from the frame like this

window.onload = parent.functionname;

notice that the () are missing from the function call. this is because the call is being made inside the script not from an event handler (you could put an onload="functionname()" in the body tag of the page instead.

the parent. at the start means the function is held in the parent page (your frameset) if it is in another frame you would have to use

parent.framename.functionname;

hope this helps

rob
 
Hi,
The only thing you can do is to use onLoad even handler of the document in your frame:
<body onload=&quot;loadingFinished()&quot;>

loadingFinished() should be described in <head> of that page or, which is better in case you have many pages, in external .js file.

good luck


 
Here's an explanation to why you don't use parentheses when saying
Code:
window.onload=parent.functionName;

Code:
parent.functionName
, like all functions, is an object. It stores a value, has a
Code:
.toString()
method, and can be referenced (another word for being pointed to). When you say &quot;Mr. Arnold&quot;, you are referring to the real person through his name. Then, when you say &quot;he&quot;, it points to &quot;Mr. Arnold&quot;, which in turn points to the person. Likewise, when you say
Code:
myVariable=myFunction;
what happens is this:
Code:
myFunction
is a pointer to the real function.
Code:
myVariable
then becomes a pointer to
Code:
myFunction
, which, as before stated, is a pointer to the function itself.

Now, when you say
Code:
window.onload=parent.functionName
, what happens, is that
Code:
onload
becomes a pointer to
Code:
parent.functionName
, which is a pointer to the real function. When the page loads, the JavaScript interpreter automatically calls function
Code:
onload()
. That code calls the function that
Code:
window.onload
points to, and we're all happy.

I hope you didn't totally go huh?? ;-)
bluebrain.gif
blueuniment.gif
 
I think I didn´t explain my problem very well. Sorry.
Suppose I have links on frameA that load pages on frameB by calling a function, say, loadPage( url , frameB ). I would like loadPage() to behave like this:

function loadPage(url,target){
target.location=url;
while( targetHasNotFinishedLoadingTheUrl )
{
/* Wait, because I don't want my users to click
a link while frameB hasn't finished loading a page */
}
}

Any ideas ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top