Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    Ipswich
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    reseting a timer

    thanks for all the help so far!!

    My page is split into three frames a header a menu and a main.
    I have a countdown timer in the header which, when reaching zero times the user out.
    I want to be able to reset the timer, ie when ever the user clicks a link. therefore it only times out if the page is inactive for say 20 minutes.
    I have used the reload function on all my menu links, but it is not a suitable approach as there are so many links etc. All the script for the timeout is in the head of the header script.
    Is there another way, apart from using reload() to get the timer to "start again" when a link or action is carried out by the user?

    thanks

    Pete

  • #2
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's not totally robust (i.e. it happens whenever the user clicks on the page, not just links), but you can use

    <SCRIPT language=Javascript><!--

    function whenclicked(){
    //put your code in here, e.g. reload()

    return true; //this means that the link clicked on will be followed
    }

    document.captureevent(Event.CLICK);

    document.onclick = whenclicked;

    // --></script>

    I know that's not what you were asking for exactly, but maybe that'll help a bit. I don't know much about timers, I'm afraid.... what object do you use to do the timing??

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh, erm by the way, you may need to change the "document." to "framename."; you probably figured that out yourself...

  • #4
    New Coder
    Join Date
    Aug 2002
    Location
    Ipswich
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    timeout script

    the following is the scirpt I wrote for the time out, this is in the <head>:

    var running = false
    var endTime = null
    var timerID = null
    browser = navigator.appName

    function startTimer() {
    running = true
    now = new Date()
    now = now.getTime()
    // If middle integer set to 60, then just change far right integer to number of mins required
    endTime = now + (1000 * 60 * 40)
    showCountDown()
    }

    function showCountDown() {
    var now = new Date()
    now = now.getTime()
    if (endTime - now <= 0) {
    stopTimer()
    parent.maintask.location.href ='timeOut.htm';
    } else {
    var delta = new Date(endTime - now)
    var theMin = delta.getMinutes()
    var theSec = delta.getSeconds()
    var theTime = theMin
    theTime += ((theSec < 10) ? ":0" : ":") + theSec
    if (document.layers)
    {
    document.ns4timer.document.ns4timer2.document.write(theTime);
    document.ns4timer.document.ns4timer2.document.close();
    }
    if (document.all)
    {
    timer.innerHTML = '<font size=2>' + theTime + '</font>';
    }
    if (document.getElementById && document.createRange)
    {
    rng = document.createRange();
    el = document.getElementById("N6timer");
    rng.setStartBefore(el);
    htmlFrag = rng.createContextualFragment(theTime);
    while (el.hasChildNodes())
    el.removeChild(el.lastChild);
    el.appendChild(htmlFrag);
    }
    if (running) {
    timerID = setTimeout("showCountDown()",1000)
    }
    }
    }


    function stopTimer() {
    clearTimeout(timerID)
    running = false
    if (document.layers)
    {
    document.ns4timer.document.ns4timer2.document.write("0:00");
    document.ns4timer.document.ns4timer2.document.close();
    }
    if (document.all)
    {
    timer.innerHTML = '<font size=2>0:00</font>';
    }
    if (document.getElementById && document.createRange)
    {
    rng = document.createRange();
    el = document.getElementById("N6timer");
    rng.setStartBefore(el);
    htmlFrag = rng.createContextualFragment("0:00");
    while (el.hasChildNodes())
    el.removeChild(el.lastChild);
    el.appendChild(htmlFrag);
    }
    }

    to start the timer an onLoad=startTimer() is placed in the body tag of the header.

  • #5
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so, you're basically needing to change the variable endTime?

    You could use the code I've given you, and place it in the header. I think it should work. Set StartTimer as the function to run onClick, and put "return true;" at the end of StartTimer.

    Does it work?

  • #6
    New Coder
    Join Date
    Aug 2002
    Location
    Ipswich
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm just implementing it at the mo, I'll let you know.

    Cheers for the help

  • #7
    New Coder
    Join Date
    Aug 2002
    Location
    Ipswich
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I couldn't seem to get it to work. I'm not sure if I implemented it correctly - I have only been doing javascript for a week.

  • #8
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, should look like:


    function startTimer() {
    running = true
    now = new Date()
    now = now.getTime()
    // If middle integer set to 60, then just change far right integer to number of mins required
    endTime = now + (1000 * 60 * 40)
    showCountDown()

    return true;
    }

    windows.frames('<menuframename>').captureevent(Event.CLICK);
    windows.frames('<menuframename>').onclick = startTimer;


    If that doesn't work, try putting the last two lines in the menu frame's head (in script tags, of course!), putting "document" instead of "windows.frames('<menuframename>')". If that doesn't work immediately, you could try putting "windows.frames('<headerframename>')." before startTimer. After that, I'm beginning to run out of ideas...

  • #9
    New Coder
    Join Date
    Aug 2002
    Location
    Ipswich
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no joy I'm afraid. Thanks for your help anyway. Much appreciated.


  •  

    Posting Permissions

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