批量保存 cookie 的最佳方法是什么?
What is the best way to mass-save cookies?
我一直在开发一个相当大的程序,其中包含许多在浏览器中运行的 JS 变量。批量保存数百个变量然后按下按钮批量加载它们的最佳方法是什么?我正在考虑使用函数循环并循环遍历每个变量,但我不太确定该怎么做。
有人可以帮我解决这个问题吗?
为什么要使用 cookie?每次用户打开任何页面时,它们都会被发送回您的服务器。我会使用 localStorage (CanIUse) and the JSON.stringify (CanIUse) 将具有所有属性的对象保存到可读实体中。
var propertiesContainer = {
"prop_one": 1,
"prop_two": 2,
"prop_three": 3
};
localStorage.setItem("properties", JSON.stringify(propertiesContainer ));
毕竟您可以使用 getItem 读取属性:
console.log(localStorage.getItem("properties"));
我一直在开发一个相当大的程序,其中包含许多在浏览器中运行的 JS 变量。批量保存数百个变量然后按下按钮批量加载它们的最佳方法是什么?我正在考虑使用函数循环并循环遍历每个变量,但我不太确定该怎么做。
有人可以帮我解决这个问题吗?
为什么要使用 cookie?每次用户打开任何页面时,它们都会被发送回您的服务器。我会使用 localStorage (CanIUse) and the JSON.stringify (CanIUse) 将具有所有属性的对象保存到可读实体中。
var propertiesContainer = {
"prop_one": 1,
"prop_two": 2,
"prop_three": 3
};
localStorage.setItem("properties", JSON.stringify(propertiesContainer ));
毕竟您可以使用 getItem 读取属性:
console.log(localStorage.getItem("properties"));