I want to register if user has been on the page for a while (waiting for some content to load) or has just came to a page.. What would be the best way to do that? I am using Rails and jquery.
Thanks
I want to register if user has been on the page for a while (waiting for some content to load) or has just came to a page.. What would be the best way to do that? I am using Rails and jquery.
Thanks
All users will "come" to the page but if you want to be alerted after they're there for a specific amount of time you could set a timer to send an ajax request after a number of seconds.
For example, the following code would execute the function inform
after every 5 seconds. Informing you that the user is still waiting...
setTimeout("inform()",5000);
The function inform
would be an AJAX request which informs the backend that the user is waiting. If you only want the request to fire once or after a number of runs stop firing then you could remove it with clearTimeout()
.
If you want the timeout to only run while the user is waiting on a specific piece of content to load. You could have the clearTimeout()
execute when the content you expect will be delayed returns.
You can find some more info on timeouts here.
Javascript setTimeout ok for you?
It will kick off some code after however long you set it for.
You can watch mouse movement, but that's about the best you're going to get for indication of a user still being there without listening to the click event. But there is no way for javascript to tell if it is the active tab or if the browser is even open. (well, you could get the width and height of the browser and that'd tell you if it was minimized)