Home arrow Tutorials arrow Measuring users' time on a page

Web Development

Welcome to Web Development section. Please choose a category. 
 
  • Hrvatski tutorijali
    Ovdje su objavljeni razni tutorijali na hrvatskom jeziku na temu PC, programiranje, web development, savjeti, trikovi, optreba racunala itd.
  • Tips / Tricks
    Articles about various tips and tricks concerning Windows, Linux and other OS usage.
  • JavaScripts
    Code snippets, tutorials and tricks for JavaScrip language.
  • PHP & MySQL
    Tutorials, code examples, tips and tricks for PHP and MySQL development.
  • Tutorials
    Place for tutorials about using various application in best and simplest way.
Measuring users' time on a page Print E-mail
(0 votes)

Measuring users' time on a page
Sunday, 17 June 2007

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>
 
< Prev   Next >
What's your favorite Internet browser?
 

Login






Lost Password?
No account yet? Register

Tools

Coming soon...

Partners

Syndicate