Click to See Complete Forum and Search --> : Warning the user that their session is about to timeout


ejrhodes
05-20-2003, 03:35 PM
My javascript knowledge is real weak so this may be easy or impossible, I dont know.

Basically onLoad I call a function called TimeIt(). The idea is that TimeIt sets the idle time for a page. After 2 minutes and 10 secs, it refreshes the page. I am trying to insert another if statement that will popUp a window warning them that they will be logged out. If they click yes, my goal is to have the session in the parent window reset after the submit. Any ideas on how to do this would be appreciated. my code as is, is below:


function TimeOut()
{
sec--;
if (sec == -1) { sec = 59; min--; }
if (min == 2) {
popUp("session.asp");
}

if (min == 0 && sec == 0) {
window.location.href= window.location;
}
else down = setTimeout("TimeOut()", 1000);
}
function TimeIt()
{
min = 2;
sec = 10;
TimeOut();
}


thanks guys


ps. Function popUp is a function that does a standard popUp window and is in the same .js file.

Jona
05-20-2003, 03:58 PM
Why not try:


var timeUp = setTimeout("openExit();", 130000);

function openExit(){
window.open("session.asp","sessionOver");
location.reload();
}


Unless I'm missing something important..

ejrhodes
05-20-2003, 04:05 PM
Originally posted by Jona
Why not try:


var timeUp = setTimeout("openExit();", 130000);

function openExit(){
window.open("session.asp","sessionOver");
location.reload();
}


Unless I'm missing something important..


The reason I dont want to do a reload on the main page is it could be a form that they have started, left and are in the process of filling out again. The system that this is sitting in is a project management/ticket management system. We have techs that start to fill out the ticket info in a page, leave and come back. We have to have a small ASP timeout because of the number of concurrent sessions.

My idea was 1 minute left in the timeout, popup a box. On submit, it would post to an asp page which would reset the ASP session, and that ASP page onLoad would reset the timeUp variable in the parent window. If the user fails to respond to the popup box in 1 minute, I want it to close the child window and refresh the main window.

Thanks for the response.

Jona
05-20-2003, 04:14 PM
Oh, I see.


<script type="text/javascript">
<!--
var timeUp;

function TimeIt(){
timeUp = setTimeout("warn();", 60000);
}

function warn(){
var warner = window.open("warnthem.asp", "warn");
clearTimeout(timeUp);
warner.document.forms[0].onsubmit = "resetTime();"
}

function resetTime(){
timeUp = setTimeout("warn();",60000);
}
// -->
</script>


In your body tag use the onload="TimeIt();" function.

In your warnthem.asp file you'll need this code:


<script type="text/javascript">
<!--
var timer = setTimeout("realGone()", 60000);
function realGone(){
parent.location.reload();
self.close();
}
// -->
</script>

ejrhodes
05-20-2003, 04:39 PM
Originally posted by Jona
Oh, I see.


<script type="text/javascript">
<!--
var timeUp = setTimeout("warn();", 60000);

function warn(){
var warner = window.open("warnthem.asp", "warn");
warner.document.forms[0].onsubmit = "resetTime();"
}

function resetTime(){
timeUp = setTimeout("warn();",60000);
}
// -->
</script>




In your warnthem.asp file you'll need this code:


<script type="text/javascript">
<!--
var timer = setTimeout("realGone()", 60000);
function realGone(){
parent.location.reload();
self.close();
}
// -->
</script>



I think I see what you are doing here. I am a little unsure how to call your original timeout function. What do I put in the body onLoad tag to make this work? Since I call body onLody TimeIt() in all my pages, how would i reword your solution so that this function call will call your code? thanks again, looking at your solution, I think it will do exactly what I want.

ejrhodes
05-20-2003, 04:52 PM
My javascript is as follows:

function TimeIt()
{
var timeUp = setTimeout("warn();", 10);
}



function warn(){
var warner = window.open("warnthem.asp", "warn");
warner.document.forms[0].onsubmit = "resetTime();"
}

function resetTime(){
timeUp = setTimeout("warn();",60000);
}


My Body Tag is as follows
<body topmargin="0" leftmargin="0" text="#000000" link="#00FFFF" vlink="#00FFFF" alink="#00FFFF" Onload="TimeIt();">

I get an Object Expected Error, what am I doing wrong? Also, is this an idle timeout or a pure time timeout? Thanks a lot, this is a huge issue as I got a lot of calls from people that were not happy they were locked out without a warning.

Jona
05-20-2003, 04:57 PM
I've edited my post with the code in it. Your code declares the variable to be local, rather than global. You must declare your variable global by putting it outside of any function first, otherwise it will be local and only accessible/defined in that function exclusivly.

ejrhodes
05-20-2003, 05:16 PM
Originally posted by Jona
I've edited my post with the code in it. Your code declares the variable to be local, rather than global. You must declare your variable global by putting it outside of any function first, otherwise it will be local and only accessible/defined in that function exclusivly.

I got another object expected error.

I commented out
clearTimeout(timeUp);
and the pop-up worked. Is this an idle timeout, or will the window pop-up no matter what? Can I make it an idle time-out so that the timeout clock is reset everytime the user clicks, move the mouse, enters text? Also, how would I add the following parameters to the text box.

toolbar=0,scrollbars=yes,location=0,titlebar=0,statusbar=0,menubar=0,resizable=1,width=500,height=40 0,left = 150,top = 100


Thanks sooooo much for your help. I really appreciate it.

Jona
05-20-2003, 05:19 PM
Use this in your body tag:


<body onload="TimeIt();" onmousemove="resetTimer();" onclick="resetTimer();" onkeypress="resetTimer();">


This will make the timer reset every time the user clicks, moves the mouse, or types any text in the document.

ejrhodes
05-20-2003, 05:44 PM
Originally posted by Jona
Use this in your body tag:


<body onload="TimeIt();" onmousemove="resetTimer();" onclick="resetTimer();" onkeypress="resetTimer();">


This will make the timer reset every time the user clicks, moves the mouse, or types any text in the document.

SWEET, you are probably killing yourself for answering this question to begin with :)

One last error, my warnthem.asp page is as follows:


<html>
<head>
<script type="text/javascript">
<!--
var timer =
setTimeout("realGone()", 60000);
function realGone(){
parent.location.reload();
self.close();
}
// -->
</script>
</head>
<body>
<form method="Post" action="" name "logout">
You are about to be logged out. Click submit to stay logged in
<input type="submit" name="submit" value="stay logged in">
</form>
</body>
</html>


The Javascript functions on the main page are:

var timeUp;

function TimeIt(){
timeUp = setTimeout("warn();", 60000);
}

function warn(){
var warner = window.open("warnthem.asp", "warn");
//clearTimeout(timeUp);
warner.document.logout.onsubmit = "resetTime();"
}

function resetTime(){
timeUp = setTimeout("warn();",60000);
}



The error I get is:
"'document.logout' is null or not an object"

Jona
05-20-2003, 05:50 PM
This is an HTML error:


<form action="" name="logout">


Also, it wasn't that much of a problem for me to help you with this. This is not a common question, but it is a lengthy one, and its difficultly level, for me, is not as high as many are.

ejrhodes
05-20-2003, 05:59 PM
Originally posted by Jona
This is an HTML error:


<form action="" name="logout">


note to self, proof read before posting That said my form is now:
<html>
<head>
<script type="text/javascript">
<!--
var timer = setTimeout("realGone()", 10000);
function realGone(){
parent.location.reload();
self.close();
}
// -->
</script>
</head>
<body>
<form action="" name="logout">
You are about to be logged out. Click submit to stay logged in
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>


and I get the same error document.logout is null or not found. The window closes after the timeout, but the parent is also not being refreshed.

Jona
05-20-2003, 06:03 PM
Take out this line:


warner.document.logout.onsubmit = "resetTimer();"


And in your form on the .ASP page:


<form action="" onsubmit="parent.resetTimer();" name="logout">

ejrhodes
05-20-2003, 06:19 PM
Originally posted by Jona
Take out this line:


warner.document.logout.onsubmit = "resetTimer();"


And in your form on the .ASP page:


<form action="" onsubmit="parent.resetTimer();" name="logout">



You beat me to it, I was going to suggest that change. I have some stuff I have to play around with. Thanks for all of your help in pointing me in the right direction. I appreciate it.

Jona
05-20-2003, 06:24 PM
Thank you for thanking me. ;) I am glad you enjoy this forum's support.

nwbee
05-24-2003, 03:02 AM
Hi there!

This is a great script, exactly what I was looking for.
It's just that the timer doesn't start over after I've said, 'okay, stay logged in'.

You call the renew timer with this in the form:
parent.resetTimer()

That should do it right?
It doesn't work here...

Can you help me?

Jona
05-24-2003, 09:25 AM
Yes it should, however if it is not working please tell me what browser you're using... And what version.

You can also try using this instead: opener.resetTime();

nwbee
05-25-2003, 03:02 AM
I'm using microsoft internet explorer 6.0?

nwbee
05-25-2003, 03:15 AM
Thank you very much!


With the opener.resetTime(); it works perfect. It refreshes every time!

Jona
05-25-2003, 05:47 PM
You're quite welcome!