| Philip M |
12-03-2012 04:31 PM |
This script will redirect if no mouse movement has been detected after x seconds, but bear in mind it only works if Javascript is enabled in the browser.
Code:
<html>
<head>
<script type = "text/javascript">
var timeInSecs;
var ticker;
var tim;
function check() {
clearInterval(ticker);
clearInterval(tim);
startTimer(6); // start or re-start the timer - 6 seconds - change to 60 for one minute, 3600 for 60 minutes
}
function startTimer(secs){
document.getElementById("message").innerHTML="";
timeInSecs = parseInt(secs);
ticker = setInterval("tick()",1000);
}
function tick() {
var secs = timeInSecs;
document.getElementById("countdown").innerHTML = secs; // REMOVE AFTER TESTING
if (secs>0) {
timeInSecs--;
}
else {
clearInterval(ticker); // stop counting at zero
document.getElementById("message").innerHTML="Unless you move your mouse within 60 seconds you will be disconnected";
tim = window.setTimeout("disconnect()", 6000); // 6 seconds - change to 60000 for 60 seconds
}
}
function disconnect() {
window.location = "http://www.google.com";
}
</script>
</head>
<body onmousemove = "check()">
<div id = "countdown"></div><br>
<!--
Remove countdown div after testing unless you wish to show this.
-->
<div id = "message" style = "font-size:18pt;font-weight:bold;text-align:center;color:red;";></div>
</body>
</html>
"If you think education is expensive, try ignorance." - Derek Bok (1930-), Harvard University President
|