Browser Page idle for 3 minutes Is it possible to find out if the browser page is idle for some time and prompt to the user?

Alessandro A. Garbagnati

Hi,
This is a very simple html page that after a 1 minute (set with the IDLE_TIME variable) of total inactivity, it will diplay an alert box.
The "total" inactivity is defined using the <script for...></script> tags. As you can see the example is trapping any mouse move or click and any keypress. You can change the events according to what you need. Obviously, if you add events, you will slow down the page.

<html>
 <head>
  <title>TEST</title>
  <script>
  	var IDLE_TIME = 60000;
  	var timerID = -1;
  	
  	function resetTimer() {
  		if (timerID != -1) {
  			clearTimeout(timerID);
  			startTimer();
  		}
  	}
  	
  	function startTimer() {
  		timerID = window.setTimeout("timeOut()",IDLE_TIME);
  	}
  	
  	function timeOut() {
  		if (timerID != -1) {
	  		alert("TIMEOUT!");
  			clearTimeout(timerID);
  		}
  	}
  	
  </script>

  <script for="document" event="onmousemove()">resetTimer()</script>
  <script for="document" event="onclick()">resetTimer()</script>
  <script for="document" event="onkeydown()">resetTimer()</script>

 </head>
 <body onLoad="startTimer()">
  <h1 align="center">Inactivity test</h1>
 </body>
</html>
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact