JS寫頁面不操作則跳出
阿新 • • 發佈:2019-01-31
<script> jumpOut(0.2) //判斷使用者有沒有操作頁面 function jumpOut(time) { var userTime = (time || 2) * 60; var objTime = { init:0, time:function(){ objTime.init += 1; if(objTime.init == userTime){ alert('開啟時間超時'); } }, eventFun:function(){ clearInterval(testUser); objTime.init = 0; testUser = setInterval(objTime.time,1000); } } var testUser = setInterval(objTime.time,1000); var body = document.querySelector('html'); body.addEventListener("touchstart",objTime.eventFun); body.addEventListener("click",objTime.eventFun); } localStorage.setItem('hi','woshi 1'); localStorage.setItem('hi','woshi 22222222'); </script>