我想执行以下 JavaScript 来设置浏览器 cookie:
document.cookie = "name=value;path='/'"
这在 Firefox、Chrome 和 Safari 中运行良好。但它在 IE 中不起作用。删除路径部分或取消引用 '/'
似乎可以在 IE 中正确设置 cookie。我不是 cookie 规范方面的专家。所有在线指南似乎都引用了该路径。引用路径是必需的还是可选的?
最佳答案
根据W3Schools正确的语法如下:
With a path parameter, you can tell the browser what path the cookie belongs to. By default, the cookie belongs to the current page.
document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";
关于javascript - 使用不带引号的路径设置 cookie 是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37510764/