Skip to content Skip to sidebar Skip to footer

How To Know When User Has Closed Web Application

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

Solution 1:

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.

Solution 2:

window.onbeforeunload = function() {
  afterLogout();
};

Post a Comment for "How To Know When User Has Closed Web Application"