I think you need to do a AJAX call on unload. But the server needs to respond before the window actualy closes.
– JaapzeJun 20 '16 at 09:56
**onbeforunload** is not a proper event for your objective because it execute each time when you leave your page.
please follow https://eureka.ykyuen.info/2011/02/22/jquery-javascript-capture-the-browser-or-tab-closed-event/ to get your objective.
– Haresh KumarJun 20 '16 at 09:58