Chrome does not set cookie path for root

I set a cookie in Javascript using the following code:

setCookie('cart_items','product_name'); function setCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } 

But the cookie path is not set to root (/) in Chrome. Instead, it is set to the path from which the web page runs!

I tested IE and FF. It works great with both of these browsers ....

What could be wrong with Chrome or is it a problem with the cookie code I am using

In Chrome (16.0.912.63)

Path: / xxxxxxxx / xxxxxxx

in FF (6.0)

Way:/

in IE (9)

Way:/

+6
source share
1 answer

The reason for this is because chrome does not allow cookies to be set to local default cookies. See this answer for more information: fooobar.com/questions/71920 / ... (text from answer)

Chrome does not support cookies for local files (or, as Peter Lions mentioned, localhost *) unless you started it with the --enable-file-cookies flag. You can read about it at http://code.google.com/p/chromium/issues/detail?id=535 .

* Chrome supports cookies if you use the local IP address (127.0.0.1) directly. therefore, in the case of a local host, this may be an easier way.

+9
source

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


All Articles