Click to See Complete Forum and Search --> : Disabling timeout in frame


anifled
12-05-2003, 09:27 PM
I have a page with links. When the link is selected the linked page is displayed in the page where the link was selected. On all my pages I use the following code for time outs. The problem I have is when I select the link the timer is still going on the parent page. It doesn't reset or stop. On the child page
activity may be happening but everything times out when the parent page times out. How do I stop the timer when I am on the child page and how do I reactivate it when I exit the child page. Any help would be appreciated.


var seconds = 10;
var counter = seconds;

function countDown() {
window.status = "Session will time out in " + seconds + "seconds";
if(seconds <=0) { alert("Your session has timed out.");
window.parent.location("login.html")
}
seconds--;
window.setTimeout("countDown()",1000);
}
function resetCounter() {

seconds = counter;
}

in the body tag I do the following:
<BODY onload="countDown()" onScroll="resetCounter()" onkeypress= "resetCounter()" onclick = "resetCounter()" ondblclick = "resetCounter()" onkeydown = "resetCounter()" onkeyup="resetCounter()" onmousedown="resetCounter()" onmousemove="resetCounter()" onmouseout="resetCounter()" onmouseover="resetCounter()" onmouseup="resetCounter()" >

leonardo43
12-06-2003, 02:45 AM
I don't quite understand why you're doing this. It seems that you might be overcomplicating the simple browser action to load a new page.

Why do you have such a timeout function on a simple HTML browser action? You haven't told us enough information, like what happens when the parent page timesout if the user hasn't selected a link yet?

Is there an automatic redirect?

Pittimann
12-06-2003, 03:04 AM
Hi!

I am of the same opinion like leonardo43!
Anyway, whatever you want to do and why - your resetCounter function does nothing but reassign a value to the var seconds.

If you want to stop the timeout, you can do something like that:

<script language="JavaScript" type="text/javascript">
<!--
var seconds = 5;
var counter = seconds;
var timer;
function countDown() {
window.status = "Session will time out in " + seconds + " seconds";
if(seconds <=0) {
alert("Your session has timed out.");
window.parent.location("login.html");
}
seconds--;
timer=window.setTimeout("countDown()",1000);
}
function resetCounter() {
clearTimeout(timer);
}
//-->
</script>

Cheers - Pit

anifled
12-06-2003, 11:12 PM
What I am trying to do is to have the application timeout after a certain amount of inactivity. I want the browser to redirect to the login page. If the user doesn't select a link on the parent page or have any activity on the parent page the parent page will timeout and redirect to the home page. I am new to doing this. There may be a better way of doing this.

Thanks for the info on stopping the timer. How would I stop the timer in the parent page? When the link is selected the child page is displayed within the parent page. How would I start it again when I exit out of the child page.