0

I´m working on a webapp MVC and want to know when the user closes the browser tab, in order to destroy his session. I´m working with jsp (html, js) and java for the internal code. Some ideas?

Rene Knop
  • 1,686
  • 3
  • 13
  • 25

2 Answers2

0

You can use window.onunload function from javascript

window.unload = function () {
  //doSomething
}

or add an eventlistener to the unload event of the window in following way:

window.addEventListener('unload', function() {
  // doSomething
})";

Have a look at the full docs on more details onunload and unload event.

Pranay Tripathi
  • 1,304
  • 1
  • 14
  • 22
0

You can use this link and put your ajax session destroy there -> Run JavaScript code on window close or page refresh

after the Ajax call, you can easily get the session and invalidate/remove it!

Mehdi
  • 3,613
  • 3
  • 33
  • 65