i try to close the page even and the browser in order to logoff user,but i failed.

1.window.onunload; 2.window.onbeforeunload.

window.onunload = function() {
  differTime = new Date().getTime() - beginTime;
  if (differTime <= 5) {
    clear(CURRENT_LOGIN_INFO, false);
  } else {}
  clear(CURRENT_LOGIN_INFO, false);
};

window.onbeforeunload = function(e) {
  beginTime = new Date().getTime();
  e = e || window.event;
  if (e) {
    clear(CURRENT_LOGIN_INFO, false);
    e.returnValue = "close!!!";
  }
  clear(CURRENT_LOGIN_INFO, false);
  return "close!!!";
};

the user has been logout but actually it still here.

1 Answers

0
Michael Rooijen van On

Invalidating the user client-side is a bad practice. You should try to expire a users session server-side. That being said, you should check where you session information is kept in the browser (eg. LocalStorage, sessionStorage, Cookies). Have a look at https://www.w3schools.com/jsref/met_storage_clear.asp