"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Wednesday, August 4, 2010

Displaying page load time through javascript

Hi friends,
now it's to show page load time in web-pages and it's very simple
Demo






Sample Code
<head>
<title>Calculating Page Loading Time</title>
<SCRIPT LANGUAGE="JavaScript">
//calculate the time before calling the function in window.onload
beforeload = (new Date()).getTime();
function pageloadingtime()
{

                 //calculate the current time in afterload
                afterload = (new Date()).getTime();
                 // now use the beforeload and afterload to calculate the seconds
                secondes = (afterload-beforeload)/1000;
//Fixing to 2 decimal point
secondes = secondes.toFixed(2);
                 // If necessary update in window.status
                window.status='You Page Load took  ' + secondes + ' seconde(s).';
                 // Place the seconds in the innerHTML to show the results
                document.getElementById("loadingtime").innerHTML =
"<font color='red'>(You Page Load took " + secondes + " seconde(s).)</font>";
               
}
 
window.onload = pageloadingtime;
</SCRIPT>
</head>
<body >

</body>
</html>


Have a nice day... 'N happy Coding :)

No comments: