YET ANOTHER QUESTION ON SESSION TIMEOUT AND SESSION_ONEND()

H

HolaGoogle

hi there,
i've 2 questions for you guys....
1: is there any way to "force" a session_onend(), session timeout or
at least call my logout method when a user leaves the application
window without logging out? i.e: using the "X" in the right corner???
i'd like to reset to their default all my variables session?? is this
possible???

2: I've succesfully been able to ask the user to confirm whether he
wants to extend his session before it ends due to inactivity. This
works perfectly and my question is: if the user is not there to answer
the question is there any way to automaticaly end the session after 1
minutes without any answer???

i.e:
function UserToConfirm()
{
if (confirm('Hey...your session is about to time out extend?'))//if
the user
//is not there to answer, then force log out ho to do this?????
{
clearTimeout(SessionTimer );
}
else
{
parent.top.location.href = 'LogOut.asp';

}
}

function SetSessionTimer()
{
if(SessionTimer > 0)
{
clearTimeout(SessionTimer );
}
TimeOutID = setTimeout("UserToConfirm()",120000);//2
minutes
//before session ends
}
and i call my SetSessionTimer() method in my body onload event...


thanks a lot...
 
L

Lasse Reichstein Nielsen

hi there,
i've 2 questions for you guys....
1: is there any way to "force" a session_onend(), session timeout or
at least call my logout method when a user leaves the application
window without logging out? i.e: using the "X" in the right corner???

No. They might not even be connected to the internet when they close
the browser.
2: I've succesfully been able to ask the user to confirm whether he
wants to extend his session before it ends due to inactivity. This
works perfectly and my question is: if the user is not there to answer
the question is there any way to automaticaly end the session after 1
minutes without any answer???

Probably. Don't use a modal confirm dialog, though. You have no way
of making that go away after one minute. If you use HTML to pose
the question, you can remove it again, and then do whatever you want.

I.e., something like:
---
/**
* text : text to display for yes/no answer
* onYes : optional, function called if yes chosen
* onNo : optional, function called if no chosen
* timeout : optional, time in milliseconds before defaulting
* timeoutDefault: optional, default answer for timeout
*
* Don't omit both onYes and onNo.
*/
function myConfirm(text,onYes,onNo,timeout,timeoutDefault) {
var div = document.createElement("div");
div.style.border = "3px grey outset";
div.style.width="8em";
div.style.height="6em";
div.style.background = "grey";
div.style.position = "absolute"; // or use fixed
div.style.left = "10em";
div.style.top = "10em"; // do something to make sure it is visible
var p = document.createElement("p");
p.appendChild(document.createTextNode(text));
div.appendChild(p);
var div2 = document.createElement("div");
div2.style.textAlign = "center";
var butYes = document.createElement("input");
butYes.style.margin="0px 5px";
butYes.type="button";
butYes.value="Yes";
butYes.onclick= function(){action(true);};
var butNo = document.createElement("input");
butNo.style.margin="0px 5px";
butNo.type="button";
butNo.value="No";
butNo.onclick= function(){action(false);};
div2.appendChild(butYes);
div2.appendChild(butNo);
div.appendChild(div2);
div.style.zIndex = 1;
document.body.appendChild(div);
if (timeout) {
var timer = setTimeout(function(){action(timeoutDefault);},timeout);
}
function action(choice) {
clearTimeout(timer);
document.body.removeChild(div);
if (choice) { if (onYes) {onYes();}}
else { if (onNo) {onNo();} }
}
}
---
You can call it as, e.g.,:
---
myConfirm("Are you sure?",
function(){alert("yes");},function(){alert("no");},
5000,true);
---
You should do something more to make sure the dialogue is visible, even
if the page is scrolled down.

You can save code space by having the confirm HTML already in the page,
and just changing the actions and text.

/L
 
H

HolaGoogle

Thanks Lasse for your quick answer...i<ll try your solution and let
you know...yeah you<Re right i tried everything to make my confirm
dialog go away after 1 minute and couldn't. So i'm gonna try you way
and see what happens.

For my 1st question, i do have a logout method, is there any way that
i could use this instead of calling session_end() to force the user to
logout when he exits the application???

Thanks a lot once again....
 
H

HolaGoogle

Thanks Lasse for your quick answer...i<ll try your solution and let
you know...yeah you<Re right i tried everything to make my confirm
dialog go away after 1 minute and couldn't. So i'm gonna try you way
and see what happens.

For my 1st question, i do have a logout method, is there any way that
i could use this instead of calling session_end() to force the user to
logout when he exits the application???

Thanks a lot once again....
 
H

HolaGoogle

Hi Lasse,

étried your suggestion but it doesn't work for me. my browser doesn't
do anything...well it's ok...i try to fin some other solution....
thanks a lot though!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top