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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timeout user inactivity script error

Status
Not open for further replies.

ayva

Programmer
Jan 12, 2009
1
US
I have this script that redirects if users mouse or scrollbar is inactive for a time. Works on my mac, but on IE6 on a pc with xp, I get errors- 'time1' is undefined
do I need to do something special for IE?
any ideas?

thanks!

<script type="text/javascript">
<!--
function timer() {
time1=window.setTimeout("redirect()",1000000);
}
function redirect() {
window.location = "logout.php"
}
function detime() {
window.clearTimeout(time1);
timer();
}
// -->
</script>

<body bgcolor="#ffffff" onload="timer();
MM_preloadImages('images/Chipcreelink_roll.gif','images
/crowlink_roll.gif','images/ncheylink_roll.gif','images
/WIwhclink_roll.gif','images/purchaselink_roll.gif','images
/dvdscdslink_roll.gif','images/contactslink_roll.gif','images
/WIaithplink_roll.gif','images/thanks_roll.gif')" onmousemove="detime()"
onscroll="detime()">
 
I am on a Linux box, so I can't test this for you...but I believe that the time1 variable is declared locally. Firefox may be a little more forgiving than IE, so I suggest you try adding this:

Code:
var time1 = 0;
function timer() {
...
}

This way time1 is declared and any reference to time1 will update the global time1 variable.
 
I'd say you want to check (in "detime") whether a timer has been started or not, as "doscroll" is probably being called before the page has loaded. Something like this:

Code:
<script type="text/javascript">

	var time1 = null;

	function timer() {
		time1 = window.setTimeout('redirect();', 1000000);
	}

	function redirect() {
		window.location = 'logout.php';
	}

	function detime() {
		if (time1 !=null) {
			window.clearTimeout(time1);
			time1 = null;
		}
		timer();
	}
</script>

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top