How to delete / delete / release a cookie right away?

I want to delete the cookie that I set. If I do this by giving him an expiration date in the past, he will be marked as “expires: at the end of the session”. I noticed that other sites manage to delete cookies as soon as possible. For example, when you log out on stackoverflow, the user's cookie disappears immediately. How?

+3
source share
2 answers

You cannot influence how and when the browser destroys expired cookies.

I assume that here on SO after logging out, a redirect is issued, so the browser gets the option to delete the cookie right now.

+2
source

javascript, cookie, ( , javascript)

jquery.cookie.js .

<script type="text/javascript" src="jquery.cookie.js" ></script>

<script type="text/javascript">
  var myCookie= readCookie('myCookie');
  if (!!myCookie) {eraseCookie('myCookie');}
</script>

, , , javascript.

+1

Source: https://habr.com/ru/post/1721269/


All Articles