As I know, there is no method to detect whether user click close the browser. so you have to set the session time out value , if time out .the session is disable.
The best way to solve you problem is refresh the page just before the session will be invalid. you set the timeout value little ,if vistor left your page, the session is going to be invalid right now.
YangSB