当页面空闲2分钟时,如何使用确认按钮注销? [英] how to logout with confirm button when page opens idle for 2 mins ?

查看:64
本文介绍了当页面空闲2分钟时,如何使用确认按钮注销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai Everyone

当网站开放并闲置2分钟时,我决定重定向到登录页面,我有5到6个网页,登录网站后进入主页,如果当用户再次点击任何链接或菜单时,用户无法工作或不使用2分钟,会出现一条确认消息并重定向到登录页面并清除所有会话。

注意:可能是使用时间限制在web.config文件中



请尽快回复我...



Thans

Aravind

解决方案

下面是实现此目的的示例代码示例代码,示例代码只是为了给您一个想法。这里空闲的测试时间是3秒(你可以改变它)。如果用户没有以3秒的间隔点击它,则此示例有一个文本框,用户将被注销。



 <   html     xmlns   =  http://www.w3.org/1999/xhtml >  
< head runat = server >
< title > Untitled Page < / title >

< script >
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000; //三秒
函数onuser_activite(){
if(logoutUser){
alert(You Session Expired);
window.location.href =Logout.aspx;
}
else {
ResetLogOutTimer();
}
}
函数OnTimeoutReached(){
logoutUser = true;
}
函数ResetLogOutTimer(){
clearTimeout(timeoutHnd);
//设置新计时器
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}


< / script < span class =code-keyword>>

< / head >
< 正文 >
< 表格 id = form1 runat = 服务器 >
< span class =code-keyword>< div >
< asp:TextBox ID = tbxarea runat = server title = 在此处写下您的姓名 > < / asp:TextBox >
< / div >
< / form >

< script > document.body.onclick = onuser_activite;
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
< / script >
< / body >
< / html >


 <   html     xmlns   =  http://www.w3.org/1999/xhtml >  
< head runat = server >
< title > Untitled Page < / title >

< script < span class =code-keyword>>
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000; //三秒
函数onuser_activite(){
if(logoutUser){
alert(You Session Expired);
window.location.href =Logout.aspx;
}
else {
ResetLogOutTimer();
}
}
函数OnTimeoutReached(){
logoutUser = true;
alert(你的会话已过期);
window.location.href =Logout.aspx;
}
函数ResetLogOutTimer(){
clearTimeout(timeoutHnd);
//设置新计时器
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}


< / script < span class =code-keyword>>

< / head >
< 正文 >
< 表格 id = form1 runat = 服务器 >
< span class =code-keyword>< div >
< asp:TextBox ID = tbxarea runat = server title = 在此处写下您的姓名 > < / asp:TextBox >
< / div >
< / form >

< script > document.body.onclick = onuser_activite;
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
< / script >
< / body >
< / html >


我刚刚在下面的代码中测试过。检查

 <   html  < span class =code-attribute>   xmlns   =  http://www.w3.org/1999/xhtml >  
< head runat = 服务器 >
< title > Untitled Page < / title >

< script >
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000; //三秒钟
函数onuser_activite(){
if(logoutUser){
;
}
else {
ResetLogOutTimer();
}
}
函数OnTimeoutReached(){
logoutUser = true;
alert(你的会话已过期);
window.location.href =Logout.aspx;

}
函数ResetLogOutTimer(){
clearTimeout(timeoutHnd);
//设置新计时器
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}


< / script < span class =code-keyword>>

< / head >
< 正文 >
< 表格 id = form1 runat = 服务器 >
< span class =code-keyword>< div >
< asp:TextBox ID = tbxarea runat = server title = 在此处写下您的姓名 > < / asp:TextBox >
< / div >
< / form >

< script > document.body.onclick = onuser_activite;
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
< / script >
< / body >
< / html >


Hai Everyone
I am decide to redirect to login page when website is open and idle for 2 mins,i have 5 to 6 web pages,after login to website it goes to main page,if user not work or it doesn't use for 2 mins when again user click any link or menus one confirm message is appear and redirect to login page and clear all sessions.
Note: May be use time limit in web.config file

Pls reply me asap...

Thans
Aravind

解决方案

Below is the sample code of one the way achieving this, sample code will just to give you an idea. Here idle time for testing is 3 second (you can change that). This sample got one text box if user does not click on it with 3 sec interval user will be logged out.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

 <script>
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000;// Three Second
function onuser_activite(){
    if(logoutUser){
    alert("You Session Expired");
    window.location.href = "Logout.aspx";
    }
    else{
        ResetLogOutTimer();
    }
}
function OnTimeoutReached(){
logoutUser = true;
}
function ResetLogOutTimer(){
clearTimeout(timeoutHnd);
// set new timer
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}


</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="tbxarea" runat="server" title="Write your name here"></asp:TextBox>
    </div>
    </form>

    <script>document.body.onclick = onuser_activite;
    timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
    </script>
</body>
</html>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

 <script>
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000;// Three Second
function onuser_activite(){
    if(logoutUser){
    alert("You Session Expired");
    window.location.href = "Logout.aspx";
    }
    else{
        ResetLogOutTimer();
    }
}
function OnTimeoutReached(){
logoutUser = true;
alert("You Session Expired");
    window.location.href = "Logout.aspx";
}
function ResetLogOutTimer(){
clearTimeout(timeoutHnd);
// set new timer
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}


</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="tbxarea" runat="server" title="Write your name here"></asp:TextBox>
    </div>
    </form>

    <script>document.body.onclick = onuser_activite;
    timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
    </script>
</body>
</html>


I just tested below code. Check it

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

 <script>
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000;// Three Second
function onuser_activite(){
    if(logoutUser){
;
    }
    else{
        ResetLogOutTimer();
    }
}
function OnTimeoutReached(){
logoutUser = true;
    alert("You Session Expired");
    window.location.href = "Logout.aspx";

}
function ResetLogOutTimer(){
clearTimeout(timeoutHnd);
// set new timer
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}


</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="tbxarea" runat="server" title="Write your name here"></asp:TextBox>
    </div>
    </form>

    <script>document.body.onclick = onuser_activite;
    timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
    </script>
</body>
</html>


这篇关于当页面空闲2分钟时,如何使用确认按钮注销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆