ho*****@yahoo.c om (HolaGoogle) writes:
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,time out,timeoutDefa ult) {
var div = document.create Element("div");
div.style.borde r = "3px grey outset";
div.style.width ="8em";
div.style.heigh t="6em";
div.style.backg round = "grey";
div.style.posit ion = "absolute"; // or use fixed
div.style.left = "10em";
div.style.top = "10em"; // do something to make sure it is visible
var p = document.create Element("p");
p.appendChild(d ocument.createT extNode(text));
div.appendChild (p);
var div2 = document.create Element("div");
div2.style.text Align = "center";
var butYes = document.create Element("input" );
butYes.style.ma rgin="0px 5px";
butYes.type="bu tton";
butYes.value="Y es";
butYes.onclick= function(){acti on(true);};
var butNo = document.create Element("input" );
butNo.style.mar gin="0px 5px";
butNo.type="but ton";
butNo.value="No ";
butNo.onclick= function(){acti on(false);};
div2.appendChil d(butYes);
div2.appendChil d(butNo);
div.appendChild (div2);
div.style.zInde x = 1;
document.body.a ppendChild(div) ;
if (timeout) {
var timer = setTimeout(func tion(){action(t imeoutDefault); },timeout);
}
function action(choice) {
clearTimeout(ti mer);
document.body.r emoveChild(div) ;
if (choice) { if (onYes) {onYes();}}
else { if (onNo) {onNo();} }
}
}
---
You can call it as, e.g.,:
---
myConfirm("Are you sure?",
function(){aler t("yes");},func tion(){alert("n o");},
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
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'