ถ้ามีการ คลิก mouse ใดๆลงบน page ก็ reset Idle time เริ่มนับใหม่
โค้ด: เลือกทั้งหมด
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
//new logic check timeout
var timeOutMin = 30;
var timeOut = (timeOutMin==null)?30:timeOutMin;
var idleTime = 0;
var idleInterval = setInterval(timerIncrement, 3000); // 3 secs
document.onmousedown = function()
{
idleTime = 0;
};
document.onkeydown=function(e)
{
idleTime = 0;
}
function timerIncrement() {
idleTime = idleTime + 1;
document.getElementById('myspan').firstChild.data= "Idle Time -> " + idleTime + " <- without mouse click if > 30 go to google.com , to reset idle time just click on page" ;
if (idleTime > timeOut) {
top.location.href = 'www.google.com';
}
}
</script>
</head>
<body>
<span id="myspan">Idle Time without mouse click if > 30 go to google.com : </span>
</body>
</html>