Javascript cookie delete

后端 未结 4 2028
隐瞒了意图╮
隐瞒了意图╮ 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:45

    Set it it to expire to a time in the past. Function from http://techpatterns.com/downloads/javascript_cookies.php

    function Delete_Cookie( name, path, domain ) {
        if ( Get_Cookie( name ) ) document.cookie = name + "=" +
          ( ( path ) ? ";path=" + path : "") +
          ( ( domain ) ? ";domain=" + domain : "" ) +
          ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
    

提交回复
热议问题