0

The problem is that when I refresh the browser the default pop appears with leave and stay buttons. It executes the AJAX code on both stay and leave buttons.

I just want to execute it when I wish to leave the page only so that the user will be logged out on click of leave.

window.top.onbeforeunload = function() {
  clearSession;
  return 'Done';
}

function clearSession() {
  var xmlHttp;
  try {
    xmlHttp = new XMLHttpRequest();
  } catch (e) {
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  // xmlHttp.onreadystatechange=handleOnReadyStateChange;

  xmlHttp.open("POST", "/navigate.html?action=logout", false);

  xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

  xmlHttp.send();
  setTimeout(function() {
    window.top.location.href = '/Login.html';
  }, 1000);
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
rishi
  • 1
  • 3

0 Answers0