網頁長時間不操作自動回到登陸頁面
阿新 • • 發佈:2019-01-25
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body id="1"> 123412 </body> </html> <script src="mui-master/examples/hello-mui/js/jquery-2.0.3.min.js"></script> <script type="text/javascript"> var maxTime = 5; // seconds var time = maxTime; document.body.addEventListener("mousemove", function() { time = maxTime; // reset }, false); var intervalId = setInterval(function() { time--; if(time <= 0) { ShowInvalidLoginMessage(); clearInterval(intervalId); } }, 1000) function ShowInvalidLoginMessage() { // 清除sessionstorage中的登入ID // 退到登陸介面 window.localStorage.removeItem("loguserId"); window.location.href="login.html"; } </script>