超时后从配置文件注销

时间:2017-10-30 13:45:48

标签: javascript jsf

以下代码中的dleMonitor和脚本无效。为什么?我认为需要在模板文件中设置超时块。我只想在超时后从配置文件中注销。请帮帮我。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">
<h:head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
  <title>
    <ui:insert name="title">CMS</ui:insert>
  </title>
  <link rel="stylesheet" type="text/css" href="/cms/css/style.css"/>
  <h:outputScript name="jsf.js" library="javax.faces" target="head"/>
  <script type="text/javascript">
     var timeOut = 1000 * 60 * 1; // 30 minutes
     var lastActivity = new Date().getTime();
     var checkTimeout;
     checkTimeOut = function(){
     if(new Date().getTime() > lastActivity + timeOut){
         window.location.replace('http://sidanmor.com');
     }else{
         window.setTimeout(checkTimeOut, 1000); // check once per second
     }
  }
  </script>
</h:head>

<body>
<p:idleMonitor timeout="5000" listener="#{LogoutServlet.service()}"
               onidle="PF('alertExpire').show();">
</p:idleMonitor>
<p:idleMonitor widgetVar="idle" timeout="300" onidle="alert('OK')" />
<div id="minHeight"></div>
<div id="outer">
  <div id="clearheader"></div>
  <div id="nav">
    <ui:include src="/templates/#{mainCms.edition}/nav.xhtml" />
  </div>

  <div id="content">
    <ui:insert name="content" > Content area. </ui:insert>
  </div>
  <div id="clearfooter"></div>
</div>
<div id="footer">
    <a href="http://com.ua/" target="_blank" title="&quot;Дт&quot;">www.com.ua</a>
    </p>
</div>
<div id="header">
  <a href="/cms" class="logo" title="ом">
    <span class="main">г</span>
  </a>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我会假设这段代码

window.location.replace('http://sidanmor.com');

将您从系统中注销。所以这里

var checkTimeout;
checkTimeOut = function(){
    if(new Date().getTime() > lastActivity + timeOut){
        window.location.replace('http://sidanmor.com');
    }else{
        window.setTimeout(checkTimeOut, 1000); // check once per second
    }
}

您要将function分配到checkTimeout变量而不执行它,因此添加此

checkTimeout(); // runs the function

将执行function并每秒再次运行它。