首先看下前端代码:
<body style="text-align: center;"> <br/>系统超时或未登录!<br/><br/> <span id="spanTime" style="color: red">5</span> 秒后自动跳转到登录界面,或者<a href='javascript:redirect()'>点击这里</a>直接登录! </body>
然后是js代码:
<script type="text/javascript"> window.onload = function(){ //1.首先声明seconds var seconds = 4; //2.声明定时器 var timer = null; //3.开启定时器 timer = setInterval(show,1000); //4.设置跳转路径
var location="<%=request.getContextPath() %>/admin/login/index.do";这里改成需要跳转的路径 //开启定时器后要执行的函数 function redirect(){ parent.parent.parent.parent.location.href = location; } function show(){ if(seconds==0){ clearInterval(timer);//清除定时器 parent.parent.parent.parent.location.href = location; return; } //将不断变化的秒数显示在页面上 document.getElementById('spanTime').innerHTML = seconds; seconds--; } }; </script>