Skip to content Skip to sidebar Skip to footer

Delete Cookie On Browser Close Not On Page Refresh

I seen many post regarding same problem but i am not getting exact solution. i want to delete cookie on browser or tab close event using javascript. I have made delete cookie funct

Solution 1:

Cookies are automatically deleted when the browser is closed, unless you specify a lifetime for the cookie.

Solution 2:

If you want to delete a cookie on browser close, better would be to check if cookie exists on page load and delete that.

Solution 3:

To delete all the cookies when browser close uses the following code

$(window).bind('beforeunload', function(event) {    
    var cookies = $.cookie();
      for(var cookie in cookies) {
        $.removeCookie(cookie);
      }
    returntrue;
});

Hope this will solve your problem.

Post a Comment for "Delete Cookie On Browser Close Not On Page Refresh"