Javascript cookie delete

后端 未结 4 2154
隐瞒了意图╮
隐瞒了意图╮ 2021-01-28 21:29

If I create a cookie in Javascript document.cookie = \'unseen\' how do I delete it when I navigate away from this page? This is the only cookie I am creating on the

4条回答
  •  臣服心动
    2021-01-28 21:54

    Sometimes

    document.cookie = 'unseen=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
    

    but sometimes need to specify path, if the first one failed (not the case of your exact code)

    document.cookie = 'unseen=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/';
    

    (or use the same library function for creating cookie, but set negative number instead of positive expiry time)

提交回复
热议问题