Click here to Skip to main content
15,113,295 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to end a user's session when they close the browser, because they never logout properly.

I need to change a value in the db after they close the browser only.
JavaScript
<script type ="text/javascript" >
      var clicked = false;
      var xmlHttp
      var browser = navigator.appName;

      function CheckBrowser() {

          if (clicked == false) {
              xmlHttp = GetXmlHttpObject();
              xmlHttp.open("GET", "../LogOut.aspx", true);
              xmlHttp.onreadystatechange = function () {
                  if (xmlHttp.readyState == 4) {
                       //alert(xmlhttp.responseText)
                  }
              }
              xmlHttp.send(null)
              if (browser == "Netscape")
                  alert("Nog een fijne dag.");
          }

          else {

              //alert("Redirected");
              clicked = false;
          }
      }

      function GetXmlHttpObject() {
          var xmlHttp = null;
          try {
              // Firefox, Opera 8.0+, Safari
              xmlHttp = new XMLHttpRequest();
          }
          catch (e) {
              //Internet Explorer
              try {
                  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
              }
              catch (e) {
                  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
              }
          }
          return xmlHttp;
      }

 </script>


That works for every browser except firefox.

Please help me with this.

Grant
Posted
Updated 3-Jul-14 1:04am
v2

1 solution

   
Comments
Member 10921710 3-Jul-14 7:07am
   
This doesn't work for firefox

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900