Code adapted from @Rod
$(function() {
timeout = setTimeout(function() {
window.location.href = "http://answall.com";
}, 120000);
});
$(document).on('mousemove', function() {
if (timeout !== null) {
clearTimeout(timeout);
}
timeout = setTimeout(function() {
window.location.href = "http://answall.com";
}, 120000);
});
In my example was added the function window.location.href
that creates the redirecting and was removed the function that caused when passing the mouse over the page excludes the content of the page.
A count has been added in milliseconds equivalent to 2 minutes (120,000 milliseconds is equal to 120 seconds, which is equal to 2 minutes, for 1 minute has 60 seconds).
After 2 minutes is redirected to http://answall.com
Now just edit it with the URL
to which you want the redirect to occur. In this case:
window.location.href = "aguarde.php";
Now is 100% functional, just the way you wanted.
Fiddle’s link
Obs: In the examples created in jsFiddle was given only 3,000 milliseconds = 3 seconds, not having to wait 2 minutes to see how it works.
If I run this code and keep moving the mouse right from the start for more than 3 seconds and then stop and leave the mouse stopped it does not run. It only runs if when I start the script, get the mouse stopped
– Alisson Acioli
And also if I have the mouse on top of the document it does not redirect, only gets out of the document
– Alisson Acioli
Show your code, you can start the timeout and only in Mousemove give a clear on it
– Rod
I edited it, test it
– Rod
Sorry to be resurrecting the topic, but I need exactly this on my system. Does this code only work in the case of the mouse? and in the case of the keyboard? because many people may be in chat for example.
– user24136
@Jose.Marcos yes, see that the event is in "Mousemove", if it is by keyboard, change it to keyup
– Rod
Right Rod, I’d actually like to for both of us. Like I would in this case?
– user24136