Displaying automatic page
update information Let's say you have a homepage
and you update it frequently. Wouldn't it be nice to include the last
update date on your page? Well, here is how you can do that:
Displaying automatic page update information
<HTML>
<HEAD></HEAD>
<TITLE> Displaying Update Info</TITLE>
<BODY bgcolor=ffffff>
<script language="JavaScript">
<!--hide script from old browsers
document.write("<h2>This page has been updated: " +
document.lastModified + "</h2>");
// end hiding -->
</script>
</BODY>
</HTML>
All you needed to do here is use the lastModified
property of the document. That's all!
Measuring users' time
on a page
This script can tell the visitors of your homepage how much time they
have spent on your page. To do that, first we create a function called
person_in(). This function creates a new date instance
which is called via the onLoad() event handler. We then
create another function called person_out() which is
called via onUnload() event handler. This function also
creates a new date instance. We then take the difference of the two
date instances, divide the result by 1000, and round the result. The
reason to divide the result by 1000 is to convert the visited time into
seconds. The result is then displayed via an alert() method.
Measuring a user's time on a page
<HTML>
<HEAD>
<TITLE>Detecting User's Time on a Page</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function person_in() {
enter=new Date();
}
function person_out() {
exit=new Date();
time_dif=(exit.getTime()-enter.getTime())/1000;
time_dif=Math.round(time_dif);
alert ("You've only been here for: " + time_dif + " seconds!")
}
</SCRIPT>
</HEAD>
<BODY bgcolor=ffffff onLoad='person_in()' onUnLoad='person_out()'>
</BODY>
</HTML>