Her

Home Web Programming JavaScript Last Modified, Loading Time, Preload your Images

Last Modified, Loading Time, Preload your Images

Author: Kyscorp.com Author's URL: www.kyscorp.com More by this author

Last Modified, Loading Time, Preload your ImagesLast Modified

This javascript code will allow you to display the date of the page's last modification:

<script language="javascript">

date=document.lastModified
day=date.charAt(3)+date.charAt(4)
month=date.charAt(0)+date.charAt(1)
year=date.charAt(6)+date.charAt(7)+date.charAt(8)+date.charAt(9)
document.write("Last modification made on : "+day+"/"+month+"/"+year)

</script>

Preload your Images

This script will allow you to preload your images and let your navigator restore them fast when your page opens, in this example we will preload the image splash.jpg that exists in the same directoruy as your page:

<script language="javascript">
if (navigator.appVersion.substring(0,1)>=3)
{
i1=new Image;
i1.src='splash.jpg';
}
</script>

Loading Time

In the following tutorial we will learn how to display the page's loading time in the status bar of your navigator, you have to insert the following code  between the <head> and </head> tags:

<script language="javascript">

NavName = navigator.appName.substring(0,3);
NavVersion = navigator.appVersion.substring(0,1);
if (NavName != "Mic" || NavVersion>=4)
{
start = new Date;
start = start .getTime();
}
function loadtime()
{
if (NavName != "Mic" || NavVersion>=4)
{
end = new Date;
end = end.getTime();
seconds = (end-start )/1000;
if (seconds>1)
{
window.status='Page loaded in ' + seconds + ' seconds.';
}
else
{
window.status='Page loaded in ' + seconds + ' second.';
}
}
}

</script>

The following code must be inserted inside the <body> tag this way :

<body onLoad="loadtime()">