I am trying to save a cookie on my website using this function in javascript
setCookie: function(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
Strange it does not work in Chrome. However, it works in Firefox.
If you change the comma instead of a comma, as shown below, it works in Chrome. But attributes are set as part of the cookie value instead of attributes that the browser can read.
document.cookie = cname + "=" + cvalue + "," + expires + ",path=/";
In addition, this is just the beginning of last week. Has anyone else noticed this? And if so, if there is a solution for this?
Thank.
UPDATE:
There seems to be a problem with the date format. I started using max-age instead with an integer value in seconds, and now it works fine even with a colon.
source
share