javascript 进度条中的Javascript会话超时倒计时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11547490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:37:03  来源:igfitidea点击:

Javascript Session time out countdown in progress bar

javascriptjsp

提问by user1080320

I need your help in getting the appropriate code for showing the count down for the session time out in the progress bar or any part of the screen.

我需要您帮助获取适当的代码,以便在进度条或屏幕的任何部分显示会话超时的倒计时。

However, these actions should be included:

但是,应包括以下操作:

First Alert: "You have 5 minutes before your session expires" Click here to continue your session. or Click here to logout

第一个警报:“您有 5 分钟的时间在您的会话到期前”单击此处继续您的会话。或点此登出

if no action in 5 mins then change the page to display "Your session has expired" and will be redirected to logout.jsp.

如果 5 分钟内没有任何操作,则更改页面以显示“您的会话已过期”,并将重定向到 logout.jsp。

I tried to find good examples, but I did not find anyone.

我试图找到好的例子,但我没有找到任何人。

Can anyone help on that issue.

任何人都可以帮助解决这个问题。

回答by Nicholas DiPiazza

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script type="text/javascript">
    var timeoutHandle = null;
    function startTimer(timeoutCount) {
        if (timeoutCount == 0) {
            window.location.href = 'logout.jsp';
        } else if (timeoutCount < 3) {
            document.getElementById('sessionTimer').innerHTML = 'You have ' + (timeoutCount * 3000)/1000 + 'seconds until timeout' ;
        }
        timeoutHandle = setTimeout(function () { startTimer(timeoutCount-1);}, '3000');
    }
    function refreshTimer() {
        killTimer(timeoutHandle);
        startTimer(3);
    }
  </script>
 </head>

 <body onload="startTimer(3)">
  <div id="sessionTimer"></div>
 </body>
</html>