我有一个关于浏览器关闭检测的问题。我的asp.net应用程序当用户突然关闭浏览器时我需要调用一个注销服务,将loginstatus从true更新为false,我这样做如下
function Logout() {
var Userid = $("#hdnfuid").val();
var branch = $("#hdnfbranch").val();
var service = LogoutService.Logout(Userid + "," + branch, SucceededCallback);
//alert(service);
}
function SucceededCallback(result) {
}
var isClose = false; ;
//this code will handle the F5 or Ctrl+F5 key
//need to handle more cases like ctrl+R whose codes are not listed here
document.onkeydown = checkKeycode
function checkKeycode(e) {
var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e)
keycode = e.which;
if (keycode == 116) {
isClose = true;
}
}
function somefunction() {
isClose = true;
}
function doUnload() {
if (!isClose) {
var selection = confirm('window is closing');
if (selection == true)
{var x=confirm("closing browser");
if(x==true)Logout();
else
return false;}
else {
return false;
}
}
但问题是,当我点击确认框的cancle时,浏览器也会关闭。 我还需要在global.asax的session_end事件上调用相同的服务 请建议我这样做的方式。 }
但问题在于