【发布时间】:2021-03-28 15:47:54
【问题描述】:
此代码在 Firefox 和 Safari 中有效,但在 Chrome 版本 33.0.1750.149 中,localStorage 在重新启动后始终为空。 (在 DevTools 中以及通过控制台访问)
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function saveStuff() {
localStorage.setItem('localKey', 'localValue');
}
</script>
</head>
<body onload="localStorage">
<button type="button" onclick="saveStuff()">Save</button>
</body>
</html>
我做错了什么?
【问题讨论】:
-
你是从 localhost 服务器运行的吗?
-
我尝试从本地主机以及部署在我的远程服务器上
-
您在浏览器运行时获得cookie了吗?见链接diveintohtml5.info/storage.html
-
if (typeof(Storage) != "undefined") 勾选此项以支持浏览器中的本地存储
-
if (typeof(Storage) != "undefined") 无效 - 支持存储
标签: html google-chrome local-storage web-storage