-1

I have tried most of ways but I am not able to delete cookies on browser close. I want to delete cookies to log out user on browser close. I tried following:

    script type="text/javascript">{

      var inFormOrLink;

     $('a').on('click', function () { inFormOrLink = true; });

       $('form').on('submit', function () { inFormOrLink = true; });
       $(window).on("beforeunload", function () {

       $.cookies('abc', null);

      $.cookies('pqr', null);

       return inFormOrLink ? "Do you really want to close?" : null;
    }

</script>

Please help me to resolve this. I have spent many days. Thanks.

Developer
  • 1,435
  • 2
  • 23
  • 48
  • 1
    along of deleting the cookie from browser... you should close the server session also... also make the cookies as session scoped so that when the browser is closed those are deleted – Arun P Johny Apr 24 '15 at 03:24

1 Answers1

0

If you really mean browser close (and not, say, tab close), the typical way to handle this is to use session cookies rather than persistent cookies. Session cookies expire when the browser closes. Nicholas Zakas wrote a good overview way back in 2009:

Without the expires option, a cookie has a lifespan of a single session. A session is defined as finished when the browser is shut down, so session cookies exist only while the browser remains open.

Trott
  • 66,479
  • 23
  • 173
  • 212