...

View Full Version : onMouseMove, reset refresh timer?



mister2quick
03-11-2009, 07:18 PM
I am setting up an HTML based information kiosk interface. One of the issues that came up is after a web page has been loaded for an extended period of time, how can it go back to the "main page" IE: inactivity timer.

Is there a way that i can setup a javascript code to reset a timer when the mouse is moved, that way it will determine inactivity on the web page? I noticed onMouseMove is the best choice, but im not sure how to use it. I currently have this setup as a static refresh on the pages in the head:



<!--REDIRECT AFTER 6 Minutes -->
<meta HTTP-EQUIV="REFRESH" content="360; url=../main.html">


Any and all help is greatly appreciated! I haven't touched Javascript in years, so im a little rusty.

Eldarrion
03-11-2009, 07:32 PM
Never mind, the code seemed to work at first, but for some reason it went haywire.

Eldarrion
03-11-2009, 07:43 PM
And here is the actually working (and tested) code:



<script type="text/javascript">
window.onload = function () {
refreshy = setTimeout("window.location=''", 5000);
}
window.onmousemove = function() {
stopCount();
startCount();
}
function stopCount() {
clearTimeout(refreshy);
}
function startCount() {
refreshy = setTimeout("window.location=''", 5000);
}
</script>


Just change the numbers in red to how much you want the user to wait until a refresh occurs (in milliseconds) and you should be set. Sorry for the previous post and the code in it going a bit haywire.

ninnypants
03-11-2009, 07:50 PM
You could cut it down even more


window.onload = function () {
refreshy = setTimeout("window.location=''", 5000);
}
window.onmousemove = function(timer, time) {
clearTimeout(timer);
timer = setTimeout("window.location =''", time);
}

mister2quick
03-11-2009, 09:38 PM
thank you so much for the quick responses! Please help me understand some things that are happening here:



window.onload = function () {
refreshy = setTimeout("window.location=''", 5000);
}
window.onmousemove = function(timer, time) {
clearTimeout(timer);
timer = setTimeout("window.location =''", time);
}


First off, should the location of the main page be in the red part? And if i am correct, when the mouse is moved, it will refresh the page with the current one and reset the timer? Also, no matter what i do to the time, it never refreshes to the main page. I've tried everything: 5, 50, 500, 5000, 360000

Eldarrion
03-11-2009, 09:48 PM
Yes, window.location points to the place you want to go to. Example:



window.onload = function () {
refreshy = setTimeout("window.location='http://www.google.com'", 5000);
}
window.onmousemove = function(timer, time) {
clearTimeout(timer);
timer = setTimeout("window.location ='http://www.gooogle.com'", time);
}


Of course, you'd want to replace it with your own location. If that doesn't do the trick, a link to a test location you have up and running would help with diagnosing the problem.

ninnypants
03-11-2009, 09:54 PM
// this sets the timer with the current time setting if the user hasn't moved
//their mouse in 5 seconds (1000 = 1second) then it will refresh to the main page
window.onload = function () {
refreshy = setTimeout("window.location='http://www.yoursite.com/'", 5000);
}
// every time the mouse is moved the timer resets giving the user more time
// before the page refreshes
window.onmousemove = function(timer, time) {
clearTimeout(timer);
timer = setTimeout("window.location ='http://www.yoursite.com/'", time);
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum