Node: Distinguish between a reload event and a browser exit with socket event

I want to run some code when a a socket is closed but only if the user didn't reload the page...

I have something like

socket.on("close", function() {
//do something here
});

The problem is that this function runs during a reload event as well...Can I somehow pause it to run at a later time with the value at that later time. I tried just using a set timeout within the callback but couldn't access the socket object anymore from within the callback.

Whats the best way to prevent the function from running if a socket connection is regained shortly after?

the main concept of my thought, is that you can never know that a user is reloading or disconnecting and never come back for 1day or so , there are ways to detect that the browser is navigating away from the website, but cant know (in server side) that it will go to the same address, or different..

Instead if any clients disconnect, of course the disconnect event will be fired to socket.io server for that socket, so taking that in account you can set a Session Variable to false you can say that the player is "disconnected" so when the client of that session "reconnects" aka reloads , the socket.io will fire an "connection" event, BUT reading the session variable you can say that the client has previously disconnected and then connected again. Timestamps could apply to this so a reconnection after 15min would have to load some extra data etc..

So you can try this with sessions (assuming that you use express or something)

sockets.on("connection",function(socket){
 if(session.isAReload){
  // this is a reconnection
 }
 socket.set("isAReload",session.isAReload /*defaults to false*/);
});

sockets.on('close',function(){
 socket.get('isAReload',function(err,isAReload){
  if(isAReload){
   // closed after reconnecting
  }else{
   /*
    just closed connection, so next time it will be a "reload" or reconnection
    a timer of lets say 30s could run to ensure that the client is reloading
    */
   session.isAReload=true; 
  }
 });
})