PDA

View Full Version : Determinining if a page has loaded completely



KrazyKid
06-18-2002, 09:30 PM
Hello all,

Is there a way to determine if a page has loaded completely?

Also is there a way to determine if items on a page have also completely loaded?

Thanks......

QuackHead
06-18-2002, 09:36 PM
Yeah...

what do you need?

if you use a Javascript, launch it when the page is finished loading...



<html>
<head>
<title>test</title>
<script language="JavaScript">
<!--
function sendMessage()
{
alert('The page has loaded completely!');
}
//-->
</script>
</head>
<body onLoad="sendMessage();">
</body>
</html>


That'll do it.

~Quack

KrazyKid
06-18-2002, 09:38 PM
I assumed that the onload is the 1st event that occurs; I want to make sure that the page has rendered completely...can this be captured?

QuackHead
06-18-2002, 09:40 PM
If the onLoad event has fired, the page has completed loading...

what more do you need?

Please explain in details what you're trying to accomplish

~Quack

KrazyKid
06-18-2002, 09:40 PM
I want to know if specific elements are loaded....

QuackHead
06-18-2002, 09:42 PM
I do not think this is possible - specific elements .. such as a picture?

KrazyKid
06-18-2002, 09:43 PM
Does the complete method work for all objects?
eg: object.complete

QuackHead
06-18-2002, 09:45 PM
Never heard of that...

sorry Krazy, you gotta give me credit though, I did answer your first question... :D

~Quack

KrazyKid
06-18-2002, 09:50 PM
Yup you are correct!

You did answer the 1st one!! Thanks...sorry for not explaining my questions as refined as possible...if there is such a method to determine if specific elements have loaded I would like to know...

Thanks again QuackHead!

JohnKrutsch
06-18-2002, 10:01 PM
I think what you are referring to is the readyState property. In IE4+ you should be able to refernece the readySate property like so:

var x= document.readyState

which should return 1 of 5 different values:

unitialized
loading
loaded
interactive
complete

so to see if a element is in fact completely loaded you could use:

var pic=document.images.picname.complete

which will return true or false depending on the current readySate of that image.

KrazyKid
06-18-2002, 10:04 PM
Thanks for the info JohnKrutsch!
Is there an NS equivalent for the readyState?

JohnKrutsch
06-18-2002, 10:15 PM
Not according to Alex Vincent's JavaScript Developers Dictionary. Sorry

KrazyKid
06-18-2002, 10:21 PM
Ok thanks!

Well, I was thinking if you were to need this event for dynamically creating objects; I suppose that if this method is only for images...

JohnKrutsch
06-19-2002, 06:42 PM
Tis should work although I download the picture so fast I can't see if it works.

<html>
<head>
<title> </title>
</head>
<body>
<div id="stats"> </div>
<img name="pic" src="http://home.centurytel.net/jcjoel2002/shed.jpg" width="640" height="480" />
<script type="text/javascript">
abc=setInterval("redy()",100);
function redy(){
var x= document.images.pic.readyState;
stats.innerHTML==x;
if(x=="complete") clearInterval(abc);
}
</script>
</body>
</html>

TrueLies
06-19-2002, 08:37 PM
My cent in.
As far as images are concerned, they are respondent to onLoad <img src.... onLoad="">
if you know how many images in a page are or how many are chached for rollovers (I bet this might be one of the underlying problems), you can instruct each image to run a function upon being loaded:
var finish=0;
function addF(){++finish}

then each image <img ... onLoad="addF()">

and for prechached you may try:

var anImm=new Image(100,100)
anImm.src="dunno.jpg"
anImm.onload=addF;

To know if a page has loaded all its graphical elements then, you recursively check with a timeout until
finish= your amount of images

maybe it is an adjunctive hint for your problem
ciao

TRACEYR
06-26-2002, 10:16 PM
I was reading this and added the following to my page to see the readystate and it returns loading.

Would this explain why the onload would not work..........

When does it become a loaded state.

Please