I found that there's no really reliable way check wether the browser-window/tab has been closed even if you use a cookie lifetime of 0 due to the way some browsers handle the cookies.
However another - obviously not always reliable - way to check wether the window/tab was closed is using JavaScript's unload events.
The combination of both should give you the best results.
Examples - vanilla JavaScript:
window.onbeforeunload = function(){
// send ajax request to invalidate the session
};
... or ...
window.unload = function(){
// send ajax request to invalidate the session
};
Example - jQuery:
$(window).bind('beforeunload', function(){
// send ajax request to invalidate the session
});
... or ...
$(window).unload(function(){
// send ajax request to invalidate the session
});
More information can be found in this question.