我正在运行一个脚本,我正在使用 ameta refresh
因为它可能会由于互联网连接或服务器停机时间或任何原因而停止:
<meta http-equiv="refresh" content="30">
该脚本需要一个起始变量,每次脚本运行时都会更新,所以我想将该变量的最新值保存在本地存储中,但通过这种方式,该值将始终被覆盖为起始值
var myId = 47911111;
localStorage.setItem('titles', myId);
首先检查您的浏览器是否支持这样的本地存储(与 sessionStorage 不同,本地存储将在页面刷新时持续存在)
if (typeof(Storage) !== "undefined") {
// Code for localStorage/sessionStorage.
// Store value
localStorage.setItem("keyName", variable);
// Retrieve value from local storage and assign to variable
var myId = localStorage.getItem("keyName");
} else {
// Sorry! No Web Storage support..
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句