I have my web application built with Play Framework 2 (backend) and AngularJS (frontend).
I need to execute some clean up calls in my backend when the user quits my web application (either by closing the browser tab or logging out).
I use play! Authenticate plugin from Joscha Feth to handle logins and logouts, so I think I could call the global method
afterLogout()
to do the cleaning, but I don't know how to generate the event.
Javascript? Html? Anything else?
There is no good way to detect this.
Typically you will keep a session and any cleanups you need to perform run when the session is cleaned up as well (because that means the user has left, ie. you're going to forget about him/her).
You can try to use
onbeforeunload
but browsers heavily restrict what you can do here, since the browser really wants to shut down, it doesn't want to wait on your code to finish. Doing any kind of AJAX is very unreliable.