I am trying to implement login Authentication module in AngularJS. Now I'm left with implementing logout.

**Logout:**

I'm updating login, logout and session info in `SessionHistory` table mainly not to allow 2 different session for a single user at a particular time.

So, function for updating logout info should be triggered for the following,

1. When user logs out from the app.
2. When user is idle (Session timeout).
3. When browser is closed.

First point I did, second point, I'll manage to do (Finding many articles and questions in stackoverflow as well). 

But I'm not sure how to trigger the logout function to update in database automatically, when browser is closed. I did not managed to get any article. Please help me with this. I'm also new to AngularJS

Thanks in advance.