我有以下目录树:
+ folder1
|--- folder2
|------ page1.html
|--- page2.html
如果我使用 JavaScript 在 page1.html
中设置一些 cookie,用于该 cookie 的路径是什么?
编辑:
让我更好地解释一下。我正在处理本地文件。 page1.html
正在通过 /home/user/.../folder1/folder2/page1.html
访问,而不是通过使用 HTTP 服务器的客户端计算机访问。
澄清一下:
似乎某些浏览器(如 Chrome)在使用 file:///
时不存储 cookie,但 Firefox 和 Internet Explorer 都会存储。
最佳答案
来自MDC page for document.cookie
:
If not specified, [the
path
argument] defaults to the current path of the current document location.
因此在您的情况下,它将是 /folder1/folder2/
。
我最初没有看到您在问题标题中指定了“本地”——不确定在我写答案时是否更新了。使用 file:///
协议(protocol)浏览时不会设置 Cookie,具体取决于浏览器。
关于javascript - 在本地 html 文件中使用 JavaScript 设置 Cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6232331/