Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending user back to start after 10 mins of Idle time?? 2

Status
Not open for further replies.

MYQUE

Technical User
May 22, 2002
25
GB
I have a full-screen kiosk style interactive presentation where the users will walk past and occasionally (hopefully!) use it.

As the presentation will not be continuously used and possibly have large periods where it is left alone I would like to find a way to make the presentation jump back to the start page as this page is more enticing to people walking by and will hopefully invite people to use it.

I am presently using the refresh Meta tag to send the presentation to the start page after 10 mins regardless of interactivity but as you can imagine this has drawbacks. I would ultimately like to send the user back ONLY when there has been no activity (idle) for 10 mins, much like how screensavers work.

The presentation consists of only two pages, the start page and the following page which is where all the interaction takes place. So the script would only have to reside on one page in total.

If anybody can tell me anything to help me along that would be great. Thanks in advance guys!! [pipe]
 
I think you could use the "onmouseover" and "onKeypress" events of the body tag to detect activity : when these events occurs, store current time in an hidden input. To go back to main page : use a timer (see my FAQ faq215-2670 to know more about timers). in this timer, compute the time between current time and the one stored in the hidden input to know if you must return to main page. Water is not bad as long as it stays out human body ;-)
 
That sounds great. However my JavaScript knowledge is somewhat very limited. I'll try and figure this out but if you or anybody could help me out here with some code it would be greatly appreciated. Thanx. [thumbsup2]
 
here is a snippet of code I'd use for such a thing :

var timer;

function startOver()
{
location.href = 'startPage.html';
}

function resetTimer()
{
timer = setTimeout("startOver()", 600000);
return true;
}

document.onmousemove = resetTimer;
document.onKeyPress = resetTimer;

This should take care of most scenarios. However be careful that no other javascript use the onmousemove and onkeypress handlers! :) Gary Haran
 
I almost did all for you :
Code:
<script language=&quot;javascript&quot;>

  var oInterval;
  var MAX_WITHOUT_ACTIVITY=10000; //number of milliseconds without activity before reload.
  
  function InitPage() {
	var oHid_h = document.getElementById(&quot;hid_lastActivity_h&quot;);
	var oHid_mn = document.getElementById(&quot;hid_lastActivity_mn&quot;);
	var oHid_s = document.getElementById(&quot;hid_lastActivity_s&quot;);
	var oDate=new Date();
	oHid_h.value = oDate.getHours();
	oHid_mn.value = oDate.getMinutes();
	oHid_s.value = oDate.getSeconds();
    oInterval = window.setInterval(&quot;VerifyActivity()&quot;, 10000); // check every 10 seconds	
  }

  function Activity() {
	var oHid_h = document.getElementById(&quot;hid_lastActivity_h&quot;);
	var oHid_mn = document.getElementById(&quot;hid_lastActivity_mn&quot;);
	var oHid_s = document.getElementById(&quot;hid_lastActivity_s&quot;);
	var oDate=new Date();
	oHid_h.value = oDate.getHours();
	oHid_mn.value = oDate.getMinutes();
	oHid_s.value = oDate.getSeconds();
  }
  
  function VerifyActivity() {
	var oHid_h = document.getElementById(&quot;hid_lastActivity_h&quot;);
	var oHid_mn = document.getElementById(&quot;hid_lastActivity_mn&quot;);
	var oHid_s = document.getElementById(&quot;hid_lastActivity_s&quot;);
	var oDate=new Date(); // current date and time
	var oLastActDate=new Date(oDate.getYear(), oDate.getMonth(), oDate.getDate(), oHid_h.value, oHid_mn.value, oHid_s.value); // last activity date and time.
	if ((oDate.valueOf() - oLastActDate.valueOf()) > MAX_WITHOUT_ACTIVITY) 
	   location.href = &quot;./anotherPage.htm&quot;;
  }
  
</script>
	</head>
	<body onload=&quot;InitPage();&quot; onmousemove=&quot;Activity();&quot; onkeydown=&quot;Activity();&quot;>
		<input id=&quot;hid_lastActivity_h&quot; type=&quot;hidden&quot; value=&quot;&quot;/>
		<input id=&quot;hid_lastActivity_mn&quot; type=&quot;hidden&quot; value=&quot;&quot;/>
		<input id=&quot;hid_lastActivity_s&quot; type=&quot;hidden&quot; value=&quot;&quot;/>
	</body>
</html>
- Change the value of &quot;MAX_WITHOUT_ACTIVITY&quot; to change the time before &quot;refresh&quot;.
- Change the &quot;./anotherPage.htm&quot; to your real page name.
- I didn't take in account the day so this script won't work if user logs at 23:59:59.
Water is not bad as long as it stays out human body ;-)
 
Thanks guys... I'll give them a try and let you know how I get on. :)
 
A star for you, Gary, your code is so simple compared to mine. Water is not bad as long as it stays out human body ;-)
 
Targol,

Using form elements is harder on mememory and processor time than using normal JS variables! :)

Thanks for the star! :) I think this forum is great for everyone to get better. I love peer review and having good programmers like you around is good for me and everyone in this forum! :) Gary Haran
 

Gary,

I'm trying to use your script & am having a little trouble getting it to work right. (yeah I am actually that crap at this!)

Anyways, I've tried various positions in the html page, above and below the body tag, to put your script and have even tried spliting it up. No luck yet. The page does go back to the start page but key presses and mouse movement doesnt seem to effect it. It jumps back regardless of user interaction.

Oh, I also needed to change your 'onmousemove' to 'onMouseMove' for it to turn blue in dreamweaver which I take it is recognised as JavaScript code then. Is this the right thing to do? What should I be doing with the code in the html page?

Thanks again.
 
I'm using IE 5.0. The final product needs to be compatible with IE versions 5 and upwards if possible.


 
I've posted the whole presentation to this location:


Please note that the images are intended for access from a CD and not the web so they are a little bit chunky. Plus the presentation is designed for use at 1024x768 fullscreen in IE5 and above (its not been tested for Nasty Netscape!).

There is a map page (the start page) and a panoramic viewer page (where the users interaction is to be detected and if idle for 10 mins then sent back to the map page.

Thanks for your help, it is very much appreciated. :)

PS Sorry about my slow response times,I'm at work and am juggling a few things at once!! [tongue]
 
Hello MYQUE

I've got the same problem with IE 5.5 sp2.

I solve it this way :

<script type=&quot;text/javascript&quot;>
var timer;

function startOver()
{
document.location.href = 'index.asp';
}

function resetTimer()
{
clearTimeout(timer);
timer = setTimeout(&quot;startOver()&quot;, 5000);
return true;
}

document.onmousemove = resetTimer;
document.onkeypress = resetTimer;

</script>

Just add &quot;clearTimeout()&quot; function, and I have lowercased the onmousemove & onkeypress, now all working good here =)

W
 
Hello again

The only thing I don't understand in my Code (see above), is why the &quot;onmousemove&quot; is activated if the mouse is ON the form but not moving. Seem's to be interpreted like &quot;onmousemove/onmouseover&quot; event.

If someone have an idea..

W
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top