The window.setTimeout() can trigger functions and events after a certain amount of time. Using them takes a certain technique that can take a while to master. I always liked to use flash for timing events and animations in my webpage, but we are in a new era with html 5 and browser scripting, so here we go.
The correct technique is to create a timeout object in a variable as so…
var booter = window.setTimeout(function(){alert('boot em out!');},10000);
you could then cancel the timed event with…
window.clearTimeout(booter);
However there is a problem with trying to call the clearTimeout() that was set in a function.
function LogTime() { var booter = setTimeout(function(){ alert('close pop and logout.change the time to 4 minutes'); }, 4000); }// end log time function
When I try to cancel this from another script outside the function, The error that “timer is undefined” is really frustrating.
The key to solving this is to declare the booter variable outside the function, and then use the variable in the function.
var booter; function LogTime() { booter = setTimeout(function(){ alert('close pop and logout.change the time to 4 minutes'); }, 4000); }// end log time function
Now this code works well, and the timed event can be cancelled when I want it to.
So need timer to loop every second.
var mytimer; function timeHer(){mytimer = setInterval(function(){//do something here every second}, 1000);}