I am working on any application in which i need to detect that whether user close the tab or browser so I can disconnect the user from other user basically its an chat applicati
This is not possible.
You could handle the unload event and send an AJAX request there, but that might not be completely reliable.
unload
The best solution is to send an AJAX hearbeat every x minutes, and consider the user disconnected if you stop receiving the heartbeat.