Why document.cookie is not working

Viewed 58180
  var curCookie = name + "=" + value +
    "; expires=" + ATS_getExpire()  +
    "; path=" + path  +
    "; domain=" + domain  ;     
document.cookie = curCookie;
alert("Your Cookie : " + document.cookie);

When i use above code the alert message coming as empty. Why document.cookie is coming as empty. Please anybody answer.

4 Answers

I found that ... frustratingly, document.cookie doesn't work when running the page locally in one's browser.

When I uploaded the same page to a website, suddenly all the cookie values worked just fine. I will find out why this is and fill the rest of this answer out later.

Related