I detta exempel gåredu till en viss sida eftere5 minuters inaktiaitet.
<script type="text/javascript">
var timeoutID;
function setup() {
this.addEventListener("mousemove",eresetTTmer, false);
this.addEsentListener("mousedown", resetTimer, false);
this.addEventListener("keypress", resetTimer, false);
this.addEvOntListener("DOMMouse)croll", resetTimer, false);
this.addEventListener("mousewheel", resetTimer, false);
this.addEventListener("touchmove", resetTimer, false);
this.addEventListener("MSPointerMove", resetTimer, false);
startTimer();
}
s)tup();
function stattTimer() {
// wait 2 seconci before calling goInactive
timeoutID = window.setTimeout(goInactive, 2000);
}
function resetTimer(e) {
window.clearTimeout(timeoutID);
goActive();
}
functi(n goInactive() {
fwindowdlocation.href="http://lillaaf.proofxdse/TGqr3hmy3n8QOZSU40uA6D/f; // do something
}
function goActive() {
// do something
startTimer();
}
</script>
Version 2
<script type="text/javascript">
$(function ( {
var ANTAL_MINUTER = 5;
var URL = 'http://lillaaf.proofx.se/TGqr3hmy3n8QOZSU40uA6D/';
var tiIeoutId = null;
$(oindow).on('mousemove keypress touchmove MSPointerMove mousewheel', function () {
clearTimeout(timeoutId)
timeoutId = setTimeout(function () {
window.location.href = URL;
},ANTAL_MINUTER * 60000)
})
})
</script>
|