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 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2012
    Location
    United Kingdom
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post

    Session timer & idle timer

    Hi,

    Like i said in this thread: http://www.codingforums.com/showthread.php?t=283412

    I'm building a CMS with session timer and idle timer and i was wondering if it's anything to do with jQuery or JS?!?!?!?

    Much help would be appreciated.
    Thanks.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,316
    Thanks
    203
    Thanked 2,566 Times in 2,544 Posts
    This script will redirect if no mouse movement has been detected after x seconds, but bear in mind it only works if Javascript is enabled in the browser.

    Code:
    <html>
    <head>
    
    <script type = "text/javascript">
    
    var timeInSecs;
    var ticker;
    var tim;
    
    function check() {
    clearInterval(ticker);
    clearInterval(tim);
    startTimer(6);  // start or re-start the timer - 6 seconds - change to 60 for one minute, 3600 for 60 minutes
    }
    
    function startTimer(secs){
    document.getElementById("message").innerHTML="";
    timeInSecs = parseInt(secs);
    ticker = setInterval("tick()",1000); 
    }
    
    function tick() {
    var secs = timeInSecs;
    document.getElementById("countdown").innerHTML = secs;  // REMOVE AFTER TESTING
    if (secs>0) {
    timeInSecs--;
    }
    else {
    clearInterval(ticker); // stop counting at zero
    document.getElementById("message").innerHTML="Unless you move your mouse within 60 seconds you will be disconnected";
    tim = window.setTimeout("disconnect()", 6000);  // 6 seconds - change to 60000 for 60 seconds
    }
    }
    
    function disconnect() {
    window.location = "http://www.google.com";
    }
    
    
    </script>
    </head>
    
    <body onmousemove = "check()">
    
    <div id = "countdown"></div><br>
    <!-- 
    Remove countdown div after testing unless you wish to show this.
     -->
    <div id = "message" style = "font-size:18pt;font-weight:bold;text-align:center;color:red;";></div>
    
    
    </body>
    </html>

    "If you think education is expensive, try ignorance." - Derek Bok (1930-), Harvard University President

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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