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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I determine if the page has loaded completely in javascript

Status
Not open for further replies.

bmdev

Programmer
May 13, 2003
29
US
Hello,

I need to execute some Javascript code in my page but only after the page has loaded completely. Is there a way to tell in Javascript if the page has completely loaded?

Thanks!!
 
Check onload event on BODY tag.

IE also has onreadystatechange event i readyState property.
 
Does the onload event of the body tag fire before or after the page loads?

Thanks!
 
i've had issues using formatting functions based off the body onload...

what i've done to get around it is call my functions with a setTimeout of 200 - 500 ms just before closing the body tag

ex:

blah blha

<script language="javascript">
setTimeout('function1(blah)',300);
setTimeout('function2(blah)',300);
</script>
</body>


this way the page has been completely streamed, gives the browser a partial second to format it self (tables etc)
before firing things off


[thumbsup2]DreX
aKa - Robert
 
bmdev: Body onload fires afer page loads (including scripts, images etc).

DreXor: in some situations this may fail. Example: function1() refers to page element that hasn't loaded yet ( APPLET/EMBED/IMG/LINK ). These elements can generate asynchronous HTTP requests and there are no guarantees they will download in 300ms. I know, make it 1000 or something :)

Dynamic changes of document structure (DOM appendChild(), innerHTML/innerText) used in body onload may cause issues you mentioned.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top