How to delete a cookie?

后端 未结 8 1544
说谎
说谎 2020-11-22 02:08

Is my function of creating a cookie correct? How do I delete the cookie at the beginning of my program? is there a simple coding?

function createCookie(name,         


        
相关标签:
8条回答
  • 2020-11-22 02:30

    Some of the other solutions might not work if you created the cookie manually.

    Here's a quick way to delete a cookie:

    document.cookie = 'COOKIE_NAME=; Max-Age=0; path=/; domain=' + location.host;
    
    0 讨论(0)
  • 2020-11-22 02:31

    would this work?

    function eraseCookie(name) {
        document.cookie = name + '=; Max-Age=0'
    }
    

    I know Max-Age causes the cookie to be a session cookie in IE when creating the cookie. Not sure how it works when deleting cookies.

    0 讨论(0)
提交回复
热议问题