tags:

views:

99

answers:

4

hi folks,

Am trying to hide a div when the user doesn't click any button on it for 15 seconds. I know how to hide and display the div by using element.style.display = 'none'; but am not able to understand how to calculate the time after last activity on the div.

Regards, Snell

+2  A: 
  • Put a timer that will hide a div after 15 seconds
  • For each click, reset the timer to 15 seconds.
Konerak
yeah .. thanks its working ..!!
snell
A: 

This clearTimeOut example might help to get you started. The instructions provided by Konerak provide the logic. :)

bebraw
A: 

If you are familier with jquery, there is the plugin known as jquery timer(the link is below), which is going to enable you run certain code in regular interval of time.

Whenever a page or a div is initiated, setup a session, and keep the time in the session variable like $_SESSION['checkedtime'] = time();

Now use the jquery timer to sent a psot request to a file which checks the value and return the activity status a basic example of that page is like this

check.php

$oldtime = $_SESSION['checkedtime'];
if($oldtime<time()-15) { return 0; }
else { return 1; }

to setup a time function see the demo page

http://www.evanbyrne.com/article/jquery-timer-plugin

Starx
thnks Starx ... but am not familiar with jquery.
snell
A: 
timedCount : function()
  {
      this.counter ++;
      if(this.counter == 15)
      {
          this.element.style.display='none';
      }
      try{ 
       t=setTimeout("timedCount()",1000);
      }catch(Ex){alert("Ex    :"+ Ex);}
  },

I am used the above function for recursion but it says timedCount is not defined. then I added dojo.hitch thinking it might be a scope problem but then it gives the error

Ex :InternalError: too much recursion

added the following lines

that=this; 
 var func = dojo.hitch(that, this.timedCount()); 
 t =setTimeout(func, 1000);
snell
after adding the dojo.hitch it gave "Ex :InternalError: too much recursion "
snell