I want to automatically after being sometimes idle by the user but not being able to do.I has used follwing javascript but nothing is going on and I have also add session timeout in web config but its also not working.Please give me some ideas.
<script type="text/javascript">
var timer1, timer2;
document.onkeypress=resetTimer;
document.onmousemove=resetTimer;
function resetTimer()
{
document.getElementById('timeoutPopup').style.display='none';
clearTimeout(timer1);
clearTimeout(timer2);
// waiting time in minutes
var wait=10;
// alert user one minute before
timer1=setTimeout("alertUser()", (60000*wait)-1);
// logout user
timer2=setTimeout("logout()", 60000*wait);
}
function alertUser()
{
document.getElementById('timeoutPopup').style.display='block';
}
function logout()
{
window.location.href='Logout.aspx';
}
}
</script>
I want to automatically after being sometimes idle by the user but not being able to do.I has used follwing javascript but nothing is going on and I have also add session timeout in web config but its also not working.Please give me some ideas.
<script type="text/javascript">
var timer1, timer2;
document.onkeypress=resetTimer;
document.onmousemove=resetTimer;
function resetTimer()
{
document.getElementById('timeoutPopup').style.display='none';
clearTimeout(timer1);
clearTimeout(timer2);
// waiting time in minutes
var wait=10;
// alert user one minute before
timer1=setTimeout("alertUser()", (60000*wait)-1);
// logout user
timer2=setTimeout("logout()", 60000*wait);
}
function alertUser()
{
document.getElementById('timeoutPopup').style.display='block';
}
function logout()
{
window.location.href='Logout.aspx';
}
}
</script>
Share
Improve this question
asked Mar 18, 2014 at 6:30
user3247426user3247426
1273 silver badges16 bronze badges
3 Answers
Reset to default 4First argument for setTimeout is a function handle. JS Timing
<script type="text/javascript">
var timer1, timer2;
document.onkeypress=resetTimer;
document.onmousemove=resetTimer;
function resetTimer()
{
document.getElementById('timeoutPopup').style.display='none';
clearTimeout(timer1);
clearTimeout(timer2);
// waiting time in minutes
var wait=10;
// alert user one minute before
timer1=setTimeout(alertUser, (60000*wait)-1);
// logout user
timer2=setTimeout(logout, 60000*wait);
}
function alertUser()
{
document.getElementById('timeoutPopup').style.display='block';
}
function logout()
{
window.location.href='Logout.aspx';
}
} </script>
You can achieve this by adding the following code in web config:
<system.web>
<sessionState timeout="10"></sessionState>
</system.web>
Here timeout=10 implies after 10 Minutes, the session will be expired and therefore, automatic logout will be acplished
I think you can use html meta tag for this
<meta http-equiv="refresh" content="30">
This will cause your page to refresh after 30 seconds (change time as you need) and while refreshing you can check the session in your server side and can do the logic what you want.