As from the various comments above your problem is little bit clear, you want to perform some action when user is leaving the current page.
You can use unload
event
window.onunload = function(){
//give ajax call here and remove whatever you want to remove from session
}
unload
event
A user agent must dispatch this event when the DOM Implementation removes from the environment the resource (such as the document) or any dependent resources (such as images, style sheets, scripts). The document must be unloaded after the dispatch of this event type.