【问题标题】:Local html and js files opened via file:/// in browser: is it possible to use cookies in JS?在浏览器中通过 file:/// 打开的本地 html 和 js 文件:是否可以在 JS 中使用 cookie?
【发布时间】:2021-04-29 02:34:23
【问题描述】:

我正在制作一个要在本地打开的 .html 文件,因此不是通过 http:// 而是通过 file:/// 访问的

Firefox 拒绝我尝试在 javascript 中创建的 cookie,说已经有一个 cookie HTTP-Only: document.cookie = cname + "=" + cvalue + ";expires=Fri, 31 Dec 9999 23:59:59 GMT;path=/;HttpOnly;SameSite=Strict;";

有没有办法为本地页面使用 cookie?

【问题讨论】:

    标签: javascript cookies


    【解决方案1】:

    没有通过 file:/// 为本地页面设置 Cookie。更多信息请看这里:Setting Cookies using JavaScript in a local html file

    【讨论】:

      【解决方案2】:

      浏览器不会为 file:// url 协议存储 cookie,尽管它可能仍然依赖于浏览器

      例如使用 --enable-file-cookies

      启动 chrome

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-09
        • 2012-10-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多