...

View Full Version : Session Timeout - javascript



rangerbreeze
10-13-2005, 05:11 PM
I am trying to modify a product that we have, to timeout/logoff if page is inactive. Perhaps displaying a pop-up to give warning first.
The Problem I have is understanding where to put the code & the web page logic,( I am just learning web based apps.. & have had no classes in this..) I have fooled around with different scenarios & have some counters working.
But simply, 2 scenarios,
1) The main driver is index.htm, which brings up logon.htm, & then home.htm. from there other pages & a menu can be looked at. Basically, after signing on, I want to go back to logon.htm if user has been inactive...
If I put my code in index.htm, it affects the logon.htm screen. If I put it in home.htm it only works when on that screen.
Index.htm has some .js import scripts, I wondering if this is where I need to put this code, or perhaps create a seperate script & call it from index.htm.

2) also from the logon.htm screen, I want to timeout & close completely after a given time. I have some code in logon.htm that displays a timer, calls a timeout.htm that opens a "yes/no" window. I have a couple bugs.

Some code I found out here that I am using: in home.htm
This displays a clock, set at 15 secs, & go backs to logon.htm
<head>
<title>Lawson Portal</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<SCRIPT LANGUAGE="JavaScript">
var href_home = "logon.htm#OUT";

function Minutes(data) {
for (var i = 0; i < data.length; i++)
if (data.substring(i, i + 1) == ":")
break;
return (data.substring(0, i));
}
function Seconds(data) {
for (var i = 0; i < data.length; i++)
if (data.substring(i, i + 1) == ":")
break;
return (data.substring(i + 1, data.length));
}
function Display(min, sec) {
var disp;
if (min <= 9) disp = " 0";
else disp = " ";
disp += min + ":";
if (sec <= 9) disp += "0" + sec;
else disp += sec;
return (disp);
}
function Down() {
sec--;
if (sec == -1) { sec = 59; min--; }
document.timerform.clock.value = Display(min, sec);
if (min == 0 && sec == 0) {
document.location.href = href_home;
}
else down = setTimeout("Down()", 1000);
}
function timeIt() {
min = 1 * Minutes(document.timerform.clock.value);
sec = 0 + Seconds(document.timerform.clock.value);
Down();
}
</script>
</head>
--------------------
<body tabIndex="-1" onload="init();timeIt()" onunload="unloadFunc()" > etc...
--------------------
<right>
<form name="timerform">
<input type="text" name="clock" size="7" value=":18"><p>

</form>
</right>
<!-- *cab3 *end -->

</body>
================

Thank you in advance for any direction....
CB

rm-f
10-13-2005, 08:54 PM
The application server takes care about timed-out sessions. You can specify default timeout value (all sessions) in the server config file or custom (particular session) in a particular page.

AlexVN
10-14-2005, 12:19 AM
Remove the init() and unloadFunc() functions and this code will start counting and redirecting.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum