how to stop ajax refresh if user is not watching

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • canabatz
    New Member
    • Oct 2008
    • 155

    how to stop ajax refresh if user is not watching

    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 !
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    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 browsersolution s, 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

    Comment

    • canabatz
      New Member
      • Oct 2008
      • 155

      #3
      thanx

      this is what i need ,to stop the interval ,but how do i do that? :(

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        store a ref to the interval in a variable and use clearInterval() to stop it ...

        Comment

        Working...