ho*****@yahoo.com (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,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);},tim eout);
}
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
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'