In my chat application i am having the logout button and it works fine.
Now I need to logout the application when I closed the browser window also..How can I achieve
There is no exact way to do this with the clientside. There is no event that is fired when the page is exited. It should be done with the Session End event on the server.
You can try to use onbeforeunload or unload, but race conditions will prevent that from happening. AND they do not fire for browsers crashing, lost internet connection, etc.