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.
See here for a Live Example
You're using ;
instead of ,
.
Use ,
to deliminate your cookie values
var curCookie = name + "=" + value +
", expires=" + ATS_getExpire() +
", path=" + path +
", domain=" + domain;
document.cookie = curCookie;
alert("Your Cookie : " + document.cookie);
UPDATE
As of today (2021-08-25), the live example is not consistent accross browsers:
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.
Sometimes this can occur if the page is hosted on a domain listed on the public suffix list (e.g. github.io, cloudfront.net). These domains are treated specially by the browser and restrict writing cookies for security reasons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With