tags:

views:

107

answers:

3

Hi,

I want a way to know if a particular web page is completely loaded using javascript

Ex) A web page can have dynamic contents getting displayed through Ajax, or contents comming through javascript, all the images and css.I need to find out when all these contents are loaded properly and the webpage is stablilized.

I got some pointers like ondocumentready its an alternate soultion for window.onload, onreadystatechange but these solutions are unreliable sometimes it works and sometimes it doesn’t

Also the solution should be browser independent, i.e it should work for all browsers

Any pointers on this will be highly appreciated

Thanks in advance

+2  A: 

Use jQuery and its easy:

<script type="text/javascript">
    $(document).ready(function() {
        alert('doc is ready');
        });
    });
</script>
  • browser independent
  • highly reliable
  • awesome
cottsak
+1  A: 

You can also use the following. It's a shorthand version of the code posted by @cottsak

$(function() 
{ 
     // your code 
});

if you’re using jQuery.noConflict() (which is used to give control of the $ variable back to whichever library first implemented it), you can do this:

By adding jQuery.noConflict(), jquery won't conflict with $ variables of other libraries

jQuery(function($) 
{ 
       // your code
});
rahul
+1  A: 

Using pure javascript you can put javascript in the onload event of the body tag like so:

<body onload="function">

This will trigger when the page has finished loading.

Rigobert Song