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,788
  • 3
  • 15
  • 27
Rodrigo Díaz
  • 67
  • 1
  • 5

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,614
  • 1
  • 16
  • 24
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,795
  • 3
  • 36
  • 65