Unable to delete cookie from javascript

后端 未结 6 1184
名媛妹妹
名媛妹妹 2021-01-01 09:35

I am on an external site, and I am trying to delete the cookie via javascript.

I did the following in the console:

function deleteAllCookies() {
             


        
6条回答
  •  执念已碎
    2021-01-01 10:06

    I just ran into this issue and finally solved it. Your cookie is most likely not being deleted because when you set the new value, it has to match the path and domain of the original cookie you're trying to delete.

    In other words:

     document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=[something];"
    

    that "something" value needs to line up with whatever the existing cookies have set.

    JS debuggers might not give you details on what the path and domain are, but it will become obvious which one you're not matching on if you look up the value of the existing cookie in your Chrome->settings or similar panel in Firefox/Safari/IE.

    Let me know if that helps.

提交回复
热议问题