使用jQuery对话框的JavaScript中的会话超时警告

使用jQuery对话框的JavaScript中的会话超时警告

本文介绍了使用jQuery对话框的JavaScript中的会话超时警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现JavaScript会话超时弹出窗口.请帮我.我能够第一次显示弹出窗口,但是当我单击确定"时,下一分钟将弹出弹出窗口.为了进行测试,我给了3分钟的时间.请帮助我解决此问题.鼠标单击时我无法重置计时器.

I am trying to implement a javascript session time out popup. Please help me.I am able to show popup for first time but when i click ok next time popup is coming in next one minute.For testing i gave 3 min time. Please help me resolve this.I am not able to reset the timer on mouseclick.

</head>
<body>
<div id="dialog" style="display:none;" title="Dialog Title">Your session is going to expire in 10min</div>
<script>
var lefttime=4;
var interval;
setTimeout( 'ShowTimeoutWarning();', 180000 );


function ShowTimeoutWarning()
{

$( "#dialog" ).dialog( "open" );
return false;

}

$("#dialog").dialog({
autoOpen: false,
dialogClass: "no-close",
position: 'center' ,
title: 'session',
draggable: false,
width : 300,
height : 200,
resizable : false,
modal : true,
buttons: [
    {
      text: "OK",
      click: function() {
        ShowTimeoutWarning();
        $( this ).dialog( "close" );

      }
    }
  ]
});

document.onkeyup=setTimeout( 'ShowTimeoutWarning();', 180000 );
document.onkeydown=setTimeout( 'ShowTimeoutWarning();', 180000 );
document.click=setTimeout

</script>

推荐答案

您的意思是这样的吗?

您需要将变量设置为setTimeout返回值,以便您可以在设置另一个超时值之前清除该超时.

You need to set a variable to the setTimeout return value so that you can clear that timeout before setting another one.

JavaScript

var timeoutID;
resetTimeout();

function resetTimeout(){
    if( timeoutID ) clearTimeout( timeoutID );
    timeoutID = setTimeout( ShowTimeoutWarning, 180000 );
}


function ShowTimeoutWarning() {
    $( "#dialog" ).dialog( "open" );
    return false;
}


$("#dialog").dialog({
    autoOpen: false,
    dialogClass: "no-close",
    position: 'center' ,
    title: 'session',
    draggable: false,
    width : 300,
    height : 200,
    resizable : false,
    modal : true,
    buttons: [{
        text: "OK",
        click: function() {
            ShowTimeoutWarning();
            $( this ).dialog( "close" );
        }
    }]
});

document.onkeyup   = resetTimeout;
document.onkeydown = resetTimeout;
document.onclick   = resetTimeout;

这篇关于使用jQuery对话框的JavaScript中的会话超时警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 03:35