By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

how to stop ajax refresh if user is not watching

P: 155
Hi all

i got a page that is refreshing data in a grid every 4 seconds and displaying results from the database and check if something as changed!

my question is if there is 100 users that is watching the page and in some times living the page and viewing some other web sites!! ,the problem is that they eating my bandwidth for nothing!!

there is a code that can stop the refreshing if they are not watching my page?

thanks in advanced !
Mar 8 '09 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 5,390
that's a quite difficult problem ... as long as the page is open in a browser window then you just know whether the user is watching the page by implementing very browserspecific solutions (asking the browser's internals for opened and active windows/tabs) that would even require privileges to do so ... because nobody really wants you to know what pages he is looking at ... so in case it is an intranet you might be lucky with one or two browsersolutions, for a public site it is quite impossible to do ... but you could try to detect wheter the user does something on your page ... you would need to track clicks, scrolls etc. on your page and when there is no action on it for a certain amount of time you could stop the interval ...

kind regards
Mar 9 '09 #2

P: 155
this is what i need ,to stop the interval ,but how do i do that? :(
Mar 9 '09 #3

Expert Mod 5K+
P: 5,390
store a ref to the interval in a variable and use clearInterval() to stop it ...
Mar 9 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.