Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Thanked 3 Times in 3 Posts

    Timer of how long user has been at page

    I'm trying to make a timer that displays how long a user has stayed at the page. I wish to display the time in the format hh:mm:ss.

    PHP Code:
    function timeAtPage() {
    if (
    started == 0) {
    startingTime = new Date();
    startingHour startingTime.getHours();
    startingMin startingTime.getMinutes();
    startingSec startingTime.getSeconds();
    started 1;
    currentTime = new Date();
    currentHour currentTime.getHours();
    currentMin currentTime.getMinutes();
    currentSec currentTime.getSeconds();
    timeHour currentHour startingHour;
    timeMin currentMin startingMin;
    timeSec currentSec startingSec;
    document.clockForm.timeatpage.value timeHour+":"+timeMin+":"+timeSec;
    clockTimer setTimeout('timeAtPage()',1000);

    This does not change the value of the text box at all. Is this the best way of displaying the time, and what is wrong with my code?

    Any help would be greatly appreciated.
    Last edited by name _F1; 08-27-2006 at 04:26 AM.

  • #2
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    New Zealand
    Thanked 0 Times in 0 Posts

    The following script can be found at http://www.javascript.internet.com/time-date,
    It does tell you how long you have been there for but only when you leave and I suppose with a few changes it could be in a form. Also I'm not sure how to set it out like you said but if you want I could find out? Just let me know.
    <script language="javascript" type="text/javascript">
    var time=1;
    function timeHere() { time = time + 1; finalTime = time / 10; }
    function sayTime() {
    finalTime = time / 10; alert("You were on this page for " + finalTime + " seconds!"); }
    <body onload='window.setInterval("timeHere()", 100)' onunload="sayTime()">
    The internet is my Sandbox, and notepad is my Spade n' Bucket.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts