JavaScript Timer function for session time out.

<script language=”javascript” type=”text/javascript”>
document.onkeypress= resetTimer
document.onmousemove= resetTimer
document.onmousedown= resetTimer
document.Onfocus= resetTimer

var timerId;

timerId = window.setTimeout(“timeOut()”,7200000);

function resetTimer() {
window.clearTimeout(timerId);
timerId = window.setTimeout(“timeOut()”,7200000);
}

function timeOut(){
// do something here

alert(“Your session is times out. You will not be able to continue. Please login again “);
var x=1;
if(x==1){
//do something here
}
}
</script>

Published by Chaitanya

I am a family man, perpetual learner, coffee drinker, dessert eater and Happiness Engineer at Automattic. I also read, write, move, and meditate.

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: