Web browsers don't have a way to process calls on exit. However, to use a proper log in system, all you need to do, is create a session variable on start of the program and set it on the server side. Each time the client tries to communicate to the server, it compares the local variable with that on the server and, if they are different, then the user is logged out. A simple way to implement this is just to use the time stamp of when the game first connected.
The events would go something like this:
On start of game: set local session variable to empty
If local session variable is empty: User signs in and the session variable is set to current time stamp
If local session variable != server session variable: User signs in and the session variable is set to current time stamp
If client fails to get a response from the server: set session variable to empty
If client can contact server and local session variable = server session variable: client is logged in
This is only one way to handle disconnecting a client. Of course, I would supplement this with a time out so if the client had not transmitted to the server after say 5 minutes, the client would have to sign back in.
If you haven't yet, you should read up on web page security for sign in pages using session variables.