i need to delete cookie when browser is closed and already put on window.onbeforeunload along with other as following:

```
 window.onbeforeunload = function(){
        location.replace("admin.jsp?action=logout");
        deleteCookie('Times');
 }

```

with setCookie as following:

```
 function setCookie(name,value,days) {
         var expires;
         if (days) {
                  var date = new Date();
                  date.setTime(date.getTime()+(days*24*60*60*1000));
                  expires = "; expires="+date.toGMTString();
         }
         else {
                  expires = "";
              }
                  document.cookie = name+"="+value+expires+"; path=/";
     }

```

when it comes to deleteCookie, it contains as below:

```
    setCookie(name,value,-1);

```

The problem is whenever i restart browser, it always comes to window.onbeforeunload so that deleteCookie fired. I actually need this to reset my countdown timer whenever user logs in since the cookie never deleted if the counter doesn't end and user sometimes closes window/tab before it ends. So, my idea is either reset the counter when user logs in or simply delete cookie when user logs out. I still can't figure out how to code this, however. Can anyone help me out? Code snippet will be appreciated, though. CMIIW