0

i have an issue regarding browser closing detection.i my asp.net application when user closes browser abruptlly i need to call a logout service which update loginstatus from true to false,i am doing this as below

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

but the problem is that when i click cancle of confirm box in that case also browser closes. i also need to call same service on session_end event of global.asax please suggest me the way of doing this. }

but the problem is that

  • Use e.preventDefault() ? And possible duplicate of http://stackoverflow.com/questions/1565304/jquery-prevent-window-closing – Henrik Peinar Mar 25 '13 at 11:38
  • what i need to do is when below returns message and user selects LeavePage i need to call servics,but i am not able to figure it out that where should i call logout service – user2207284 Mar 25 '13 at 12:31
  • the code is function closeIt() { return "Any string value here forces a dialog box to \n" + "appear before closing the window."; if (window.event.returnValue) { alert("sty"); } else {alert("go");} } window.onbeforeunload = closeIt; – user2207284 Mar 25 '13 at 12:32

0 Answers0