1

This has left me flabbergasted. I have a site opened on my browser (say stack overflow). And from the browser console I am trying to delete the cookie. I am trying two ways as suggested by many guys online:

var cookies = document.cookie.split(";");
    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }

and the other one as giving an exact cookie name as follows:

document.cookie = '_ga=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';

After performing any of those two methods, I try enter:

document.cookie

And I see all the list of cookies with nothing changed. What am I doing wrong and how do I check if the cookie is deleted?

4
  • did you close the browser and open it back up to the page and see if the cookies are there? Commented Dec 29, 2016 at 15:21
  • 1
    what is the use of programatically deleting if I have to close the browser, open and verify. Commented Dec 29, 2016 at 15:28
  • Possible duplicate of Unable to delete cookie from javascript Commented Dec 29, 2016 at 15:38
  • may enter location.reload() -> programmatically Commented Dec 29, 2016 at 15:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.