gpt4 book ai didi

javascript - 如何读取/写入本地文件 :///HTML document? 的 cookie

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:41:16 32 4
gpt4 key购买 nike

如何使用 Javascript 或 jQuery 为本地 file:/// HTML 文档读取/写入 cookie?

这个我试过了>>

function setCookie(c_name, value, exdays)
{
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) +
((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name)
{
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++)
{
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name)
{
return unescape(y);
}
}
}

但它不起作用。

最佳答案

这取决于您的浏览器。 Chrome 例如不允许本地文件的 cookie。参见:where cookie saved for local HTML file

关于javascript - 如何读取/写入本地文件 :///HTML document? 的 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12992494/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com