Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onMouseMove, reset refresh timer?

    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:

    Code:
    <!--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.

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Never mind, the code seemed to work at first, but for some reason it went haywire.
    Last edited by Eldarrion; 03-11-2009 at 07:36 PM. Reason: See above.

  • #3
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    And here is the actually working (and tested) code:

    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.

  • #4
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    You could cut it down even more
    Code:
    window.onload = function () {
    	refreshy = setTimeout("window.location=''", 5000);
    }
    window.onmousemove = function(timer, time) {
         clearTimeout(timer);
         timer = setTimeout("window.location =''", time);
    }

  • #5
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you so much for the quick responses! Please help me understand some things that are happening here:

    Code:
    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

  • #6
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Yes, window.location points to the place you want to go to. Example:

    Code:
    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.

  • #7
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Code:
    // 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);
    }


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •