0

我有一个关于浏览器关闭检测的问题。我的 asp.net 应用程序当用户突然关闭浏览器时我需要调用一个注销服务,它将登录状态从真更新为假,我这样做如下

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;
                }                    
            }

但问题是,在这种情况下,当我单击确认框的取消时,浏览器也会关闭。我还需要在 global.asax 的 session_end 事件上调用相同的服务,请建议我这样做的方式。}

但问题是

4

0 回答 0