I'm working on an asp.net project (written awhile ago), and users say they want to be able to log out on "x'ing" out the tab or browser.
I've been looking around this site and have tried a few things with no luck. It doesn't seem like there is an easy way about this with there being different browsers.
First, here's a logout function which is called from a logout button
.
public void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
{
Response.Cookies.Clear();
Session.Clear();
HttpContext.Current.User = null;
FormsAuthentication.SignOut();
}
It would be nice if I could somehow call that when closing the tab/browser.
There is this javascript in the master page:
<script type="text/javascript">
// Copyright 2006-2007 javascript-array.com
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
// open hidden layer
function mopen(id)
{
// cancel close timer
mcancelclosetime();
// close old layer
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
// get new layer and show it
ddmenuitem = document.getElementById(id);
ddmenuitem.style.visibility = 'visible';
}
// close showed layer
function mclose()
{
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}
// go close timer
function mclosetime()
{
closetimer = window.setTimeout(mclose, timeout);
}
// cancel close timer
function mcancelclosetime()
{
if(closetimer)
{
window.clearTimeout(closetimer);
closetimer = null;
}
}
// close layer when click-out
document.onclick = mclose;
</script>
However, it doesn't seem to work. I messed around w/ the timeout
variable and no matter how long I wait after I exit the tab/browser, the cookies/session do not clear out. I know chrome
has a "continue where you left off" feature, and other browsers have similar I'm sure. Unfortunately, all of the users don't use the same browsers.
Any ideas would be most welcome!