Chrome does not save semicolon cookies

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.

+4
source share
1

, . MDN :

cookie -, / :

:

; =

; =

; =

; =

Chrome 58.0.3029.96 (64- ) .

var cname = "MyCookie";
var cvalue = "kjqwrQR1515jetrQT26jo2u5";
var expires = " ;expires=" + Date.now() + 100000;

document.cookie = cname + "=" + cvalue + expires + " ;path=/";

, cname cvalue exdays?

+2

Source: https://habr.com/ru/post/1676486/


All Articles