I have many websites running my shoutbox script, but there is a problem here:
This shoutbox refreshes itself each 10 seconds , and consider what if it happens on a crowded website!
It gives javascript error sometimes to some users
$(document).ready(function(){
updateShoutbox();
var auto_refresh = setInterval(
function ()
{
updateShoutbox();
}, 10000);
Changing the time period is one option , the other is improving the server resources . but I have a thesis here:
What if there is a way to smart up this thing as it could stop refreshing while the user is disconnected or not focused on the website window ?
I am looking for a way to condition the shoutbox refresh to only when the website window is focused and internet connecton is alive .
Thanks for the help.
In a small search I found this javascript implementation that detects when the user is idle or away.
Example:
You can stop sending ajax requests when the user is away using this implementation.
Answering the comment:
jfriend00, it tracks the interactive events in the document, using jQuery or prototype api:
Then it use timeouts to track when the user didn’t interact with the page, basically, if the user interact before the timeout is executed, then the function clear the timeout and start it again, so it’s only executed when the user don’t interact with the page:
When the user get back, it interact with the page, detect that he was away or idle by a flag, if he was away then he executes the onBack and start the setTimeout again