As christian suggested, it is true, you cant ensure that the page is actually closed or not in the client site.
You might make a workaround using
window.onbeforeunload = function () {
}
or rather going for (IE only)
if(window.event.clientX < 0 && window.event.clientY <0)
{
}
to run your code, but you will not be sure that the code will execute. The user might close the process itself which will close the browser immediately and you cant do anything with that.
So It is always better to have a logic of automatic timeout in the server. Just change the last request time to a field in server and give a timeout seed to automatically clear the session after a certain interval(preferrably the Session timeout value).
:cool: