Perform action before leaving
===

I'm working on a chatsystem and I have to delete data in the database before the user are leaving the chat...

Is it possible to perform an action triggered when the user are trying to leave?