admin管理员组文章数量:1420939
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.
本文标签: javascriptautomatically logout from pageStack Overflow
版权声明:本文标题:javascript - automatically logout from page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745319315a2653302.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论