Javascript 如何在jquery中60秒后注销?
我已经编写了如下几行代码的jqueryJavascript 如何在jquery中60秒后注销?,javascript,jquery,Javascript,Jquery,我已经编写了如下几行代码的jquery <script type="text/javascript"> var t; window.onload=resetTimer; document.onkeypress = resetTimer; document.onmouseover = resetTimer; function logout() { var answer = confirm('You will be logged out after 60 Sec
<script type="text/javascript">
var t;
window.onload=resetTimer;
document.onkeypress = resetTimer;
document.onmouseover = resetTimer;
function logout() {
var answer = confirm('You will be logged out after 60 Second');
if (answer) {
location.href = '../login/login.aspx'
}
else {
window.onload = resetTimer;
}
}
function resetTimer()
{
clearTimeout(t);
t=setTimeout(logout,10000) //logs out in 10 min
}
</script>
变量t;
window.onload=resetTimer;
document.onkeypress=重置计时器;
document.onmouseover=重置计时器;
函数注销(){
var answer=confirm('您将在60秒后注销');
若有(答复){
location.href='../login/login.aspx'
}
否则{
window.onload=重置计时器;
}
}
函数resetTimer()
{
清除超时(t);
t=setTimeout(注销,10000)//10分钟后注销
}
现在我想,如果用户在60秒后不确认,它应该在60秒后注销,也就是说,它应该重定向到登录页面。请帮忙
我 confirm()
阻止所有其他Javascript,因此当用户响应时间超过60秒时,您无法取消它
您可以使用jQueryUI对话框来完成
$(function() {
resetTimer();
document.onkeypress = resetTimer;
document.onmouseover = resetTimer;
function logout() {
var t1 = setTimeout(reallyLogout, 60000);
$("<div>You will be logged out after 60 seconds</div>").dialog({
modal: true,
buttons: {
OK: reallyLogout,
Cancel: function() {
clearTimeout(t1);
resetTimer();
$(this).dialog("close");
}
}
});
}
var t;
function resetTimer() {
clearTimeout(t);
t = setTimeout(logout, 10 * 60000); // Logout in 10 minutes
}
function reallyLogout() {
location.href = '../login/login.aspx';
}
});
$(函数(){
重置计时器();
document.onkeypress=重置计时器;
document.onmouseover=重置计时器;
函数注销(){
var t1=设置超时(reallyLogout,60000);
$(“您将在60秒后注销”)。对话框({
莫代尔:是的,
按钮:{
好的:真的注销,
取消:函数(){
清除超时(t1);
重置计时器();
$(此).dialog(“关闭”);
}
}
});
}
变量t;
函数resetTimer(){
清除超时(t);
t=setTimeout(注销,10*60000);//10分钟后注销
}
函数reallyLogout(){
location.href='../login/login.aspx';
}
});
在演示中,我将注销计时器更改为20秒,确认超时更改为10秒,这样您可以在合理的时间内对其进行测试。confirm()
会阻止所有其他Javascript,因此当用户响应时间超过60秒时,您无法取消它
您可以使用jQueryUI对话框来完成
$(function() {
resetTimer();
document.onkeypress = resetTimer;
document.onmouseover = resetTimer;
function logout() {
var t1 = setTimeout(reallyLogout, 60000);
$("<div>You will be logged out after 60 seconds</div>").dialog({
modal: true,
buttons: {
OK: reallyLogout,
Cancel: function() {
clearTimeout(t1);
resetTimer();
$(this).dialog("close");
}
}
});
}
var t;
function resetTimer() {
clearTimeout(t);
t = setTimeout(logout, 10 * 60000); // Logout in 10 minutes
}
function reallyLogout() {
location.href = '../login/login.aspx';
}
});
$(函数(){
重置计时器();
document.onkeypress=重置计时器;
document.onmouseover=重置计时器;
函数注销(){
var t1=设置超时(reallyLogout,60000);
$(“您将在60秒后注销”)。对话框({
莫代尔:是的,
按钮:{
好的:真的注销,
取消:函数(){
清除超时(t1);
重置计时器();
$(此).dialog(“关闭”);
}
}
});
}
变量t;
函数resetTimer(){
清除超时(t);
t=setTimeout(注销,10*60000);//10分钟后注销
}
函数reallyLogout(){
location.href='../login/login.aspx';
}
});
在演示中,我将注销计时器更改为20秒,确认超时更改为10秒,因此您可以在合理的时间内对其进行测试。您不能中断
confirm()
对话框。您应该使用HTML对话框。清除logoutI会话意味着如果用户在60秒后不确认,则应在60秒后注销。confirm()
将阻止其余javascript执行,直到返回true或false。它阻塞了其余的源代码。正如巴默所指出的,使用HTML对话框。您不能中断confirm()
对话框。您应该使用HTML对话框。清除logoutI会话意味着如果用户在60秒后不确认,则应在60秒后注销。confirm()
将阻止其余javascript执行,直到返回true或false。它阻塞了其余的源代码。正如Barmer所指出的,使用HTML对话框。谢谢barmar。。。你能给我提供jQueryUIT的链接吗?这个网站是jqueryui.com。谷歌不适合你吗?我在用这个我以为你想要的是文档链接,不是脚本。我不知道为什么它不适合你,它适合我。你在控制台里有什么错误吗?谢谢你barmar。。。你能给我提供jQueryUIT的链接吗?这个网站是jqueryui.com。谷歌不适合你吗?我在用这个我以为你想要的是文档链接,不是脚本。我不知道为什么它不适合你,它适合我。控制台中是否有任何错误?