Return index page if no mouse action
Posted July 12th 2013, 3:37am
I want my web return to the index page if no mouse action after 10 minutes.
Thanks for any guide
φ
Posts: 35
Joined: May 23rd 2013, 9:51pm
Likes Received: 1
Return index page if no mouse action
Posted July 12th 2013, 10:28am
This could be done with a function hooked to the javascript onmousemove event. Something like:

function back2index() {
clearTimeout(to);
to = setTimeout(window.location='/index.php', 600000);
}
var to = setTimeout(window.location='/index.php', 600000);
window.onmousemove = function() {back2index();};

Pages might be "laggy" due to the function being called every time the mouse is moved.
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Return index page if no mouse action
Posted July 12th 2013, 6:14pm
Something else to add, some people may find that it's user unfriendly, in other words, I may not be happy if I was writing a post and it just took me to the homepage.
φ
Posts: 115
Joined: May 26th 2013, 12:17am
Likes Given: 60
Likes Received: 7
Return index page if no mouse action
Posted July 12th 2013, 8:37pm
I think more than a few people would find this user-unfriendly. ;)

It's not something I would ever do on a live site, but the code does demonstrate how to set an action to activate after a period of time. One example might be to close an open chatbox window/connection after a period of inactivity.
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Return index page if no mouse action
Posted July 12th 2013, 9:14pm
Good point :) One other thing, I got a feeling that some government websites here in Australia, it logs the user out of their account for safety reasons.
φ
Posts: 115
Joined: May 26th 2013, 12:17am
Likes Given: 60
Likes Received: 7
Return index page if no mouse action
Posted July 12th 2013, 11:46pm
Daniel said:
Something else to add, some people may find that it's user unfriendly, in other words, I may not be happy if I was writing a post and it just took me to the homepage.

I forget to note about keyboard, it shoud be with mouse and keyboard inactive for a while. Besides safety reason, return to homepage shows a nice view in office. Very appreciated if you can help a full script
φ
Posts: 35
Joined: May 23rd 2013, 9:51pm
Likes Received: 1
Return index page if no mouse action
Posted July 13th 2013, 11:16am
Add this to the bottom of the code, and you should have keyboard support as well:

window.onkeypress = function() {back2index();};

Please keep this in mind:

Dion said:
Pages might be "laggy" due to the function being called every time the mouse is moved.
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357

Who is online

Users browsing this forum: No registered users and 0 guests