Javascript:Last modified

hello all, been very sick laltely, got the WORLD CUP FEVER :p in just two days we are gonna see some great matches among the nations world wide… wow… we'll all be busy talking about it, i know i will… hehehe anyways got something cool for the noobs out there…

When you are browsing some websites, you would have noticed that on the front page there will be a statement indicating the last modifed date and time. This helps the viewers know that this page was updated recently and its fresh… In my point of view its very important to have something like that.

If you also wanna have something cool like that, which also updates automatically, the folowing javascript will help you out. This trick can also be done in PHP and other server side languages, you can google for that.

Code:
<script type="text/javascript" language="javascript">
window.onload=function(){
document.getElementById('lstmod_div').innerHTML = "Last Modified on: "+ document.lastModified;
}
</script>

As you can see its just a simple javascript, using simple built-in functions. The windows.onload is used to load the function() when the page is loaded. This will then execute the getElementByID() function to create the last modified date… To use this nifty script copy the above script and paste it between the <head></head> tags. Then place a this div tag, <div id="lstmod_div"></div>, inside the <body></body> at anyplace u like… And its good to go…

I have used CSS to position and apply some design to it.. the following is the CSS code i used:
#lstmod_div {
width: 225px;
float:right;
margin-top: 0px;
margin-left: 0px;
margin-bottom:0px;
font-size:11px;
text-align:right;
color:#666;
border-color:#F3F4F4;
background-color:#FFF;
}

Hopefully you'll understand this smallscript if not comment it and i'll help you out.. đŸ˜›

For a live demo of this script click here, the website is undercontrsuction now but you'll see the script in action 

Advertisements

About this entry