Time On Page

[Total: 0    Average: 0/5]

This shows how to have a form textbox keep track of the time spent on a page.

Body Code:

<font size=+1>Timer</font><hr>
A very simple timer that will tell how much time is spent on one page.<p>
<CENTER><form name=exf1>
Time spent on this page: 
<input size=9 name=timespent>
</form><p>


<script>
 
startday = new Date();
clockStart = startday.getTime();

function initStopwatch() 
{ 
 var myTime = new Date(); 
        var timeNow = myTime.getTime();  
        var timeDiff = timeNow - clockStart; 
        this.diffSecs = timeDiff/1000; 
        return(this.diffSecs); 
} 
initStopwatch();

function getSecs() 
{ 
        var mySecs = initStopwatch(); 
        var mySecs1 = ""+mySecs; 
        mySecs1= mySecs1.substring(0,mySecs1.indexOf(".")) + " secs."; 
        document.exf1.timespent.value = mySecs1 
        window.setTimeout('getSecs()',1000); 
}
getSecs();
</script>


Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *