根据 MDN,路径为 '/' 的 cookie可在同一域中的任何位置使用。这得到了几个 不同 来源的证实。
但是,我只是没有发现这种情况。google.com
我在使用 firefox时对(不存在的)目录进行了以下测试:
> window.location = 'https://google.com/dir/file.html'
Navigated to https://google.com/dir/file.html
"https://google.com/dir/file.html"
> document.cookie
""
> document.cookie = 'key1=value1,path=/'
"key1=value1,path=/"
> document.cookie
"key1=value1,path=/"
> window.location = '/dir2/file.html'
Navigated to https://google.com/dir2/file.html
"/dir2/file.html"
> document.cookie
""
我是不是误会了什么?我究竟做错了什么?我在 Chrome 上尝试了类似的测试,结果相同。