faqts : Computers : Programming : Languages : JavaScript : Frames

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

21 of 24 people (88%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do i set an inactivity timer (based on mousemove event) from a parent frame?

Aug 25th, 2001 09:29
Tony Crosby, David Majchrzak,


<HTML>
<HEAD>
<SCRIPT>
function post_action(){
// *** DO SOMETHING *** \\
alert("You Are Innactive");
}
var tid, time, action;
function setInactivityTimer (time, action, repeat) {
  window.time = time;
  window.action = action;
  window.repeat = repeat;
  if (tid) 
    clearTimeout(tid);
  if (document.layers)
    document.captureEvents(Event.MOUSEMOVE | Event.KEYUP);
  document.onmousemove = document.onkeyup =
    function (evt) {
      setInactivityTimer(window.time, window.action, window.repeat);
      return true;
    };
  if (repeat)
    action += '; setInactivityTimer(' 
              + time + ', "' + action + '", ' + repeat + ');';
  else 
    action += '; clearEvents();';
  tid = setTimeout(action, time);
}
function clearEvents() {
  if (document.layers)
    document.releaseEvents(Event.MOUSEMOVE | Event.KEYUP);
  document.onmousemove = document.onkeyup = null;
}
setInactivityTimer(2000, 'post_action();', true);
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
 Change alert("you are innactive") to you code to be carried out when 
the timer is finished.
 To change the time of innactivity allowed before the code is set off 
change
setInactivityTimer(2000, 'post_action();', true);
 2000 being the time in miliseconds.
 Tony