(jQuery) javascript setTimeout clearTimeout
        Posted  
        
            by Tillebeck
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Tillebeck
        
        
        
        Published on 2010-06-10T14:26:50Z
        Indexed on 
            2010/06/10
            14:32 UTC
        
        
        Read the original article
        Hit count: 502
        
Hi
I try to make a page to go to the startpage after eg. 10sec of inactivity (user not clicking anywhere). I use jQuery for the rest but the set/clear in my test function are pure javascript.
In my frustation I ended up with something like this function that I hoped I could call on any click on the page. The timer starts fine, but is not reset on a click. If the function is called 5 times within the first 10 seconds, then 5 alerts will apear... no clearTimeout...
function endAndStartTimer() {
    window.clearTimeout(timer);
    var timer;
    //var millisecBeforeRedirect = 10000; 
    timer = window.setTimeout(function(){alert('Hello!');},10000); 
}
Any one got some lines of code that will do the trick? - on any click stop, reset and start the timer. - When timer hits eg. 10sec do something.
BR. Anders
© Stack Overflow or respective owner