4

I need to call a function that logsout users from the system when the browser's window is closing.

I found a function window.onbeforeunload but this also gets called when you reload the browser and I dont want the user to be logged out when he reloads the browser. I need to do it once the browser window is closed.

Is this even feasible?

Stphane
  • 3,368
  • 5
  • 32
  • 47
Ray
  • 41
  • 1
  • 5
  • theres no way, one thing you could do is logout on each close (`onbeforeunload`) and relogin using cookies. Create the cookie without a expiry date, then it will be deleted if the browser gets closed. – jsadev.net Oct 21 '19 at 11:24
  • This should help https://stackoverflow.com/questions/1631959/how-to-capture-the-browser-window-close-event?answertab=votes#tab-top – Arisen Fernandes Oct 21 '19 at 11:26
  • how can I detect if there is been no activity on browser for sometime or 5 min? – Ray Oct 21 '19 at 11:38

1 Answers1

-1

From Firefox Documentation

window.addEventListener("beforeunload", function (e) {
  var confirm_message = "\o/";

  (e || window.event).returnValue = confirm_message ; 
  return confirm_message ;                      
});

This example working on all browsers