localStorage不支持谷歌浏览器 [英] localStorage is not working on google chrome

查看:1046
本文介绍了localStorage不支持谷歌浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用浏览器 localStorage 来存储值,但在使用谷歌浏览器时,当我们使用 window.location.reload刷新页面时(刷新 localStorage.value 。例如

  localStorage.value1 = true 

重新加载后,我没有在localStorage中获取此value1对象。



相同的代码适用于mozila firefox,但不适用于chrome。
使用firefox时,localstorage值是持久的。

解决方案

LocalStorage仅支持字符串值,不支持布尔值或其他值。 / p>

存储和检索值的方法:



将值存入存储

  localStorage.setItem('value1','true'); 

从存储中检索价值

  var val1 = localStorage.getItem('value1'); 

在MDN上阅读更多信息 ..


I am using browsers localStorage to store a value, but while using google chrome, when we refresh the page using window.location.reload(), localStorage.value is flushed. e.g

localStorage.value1=true

after reloading, i am not getting this value1 object in localStorage.

Same code works on mozila firefox, but not in chrome. While using firefox, localstorage value is persistent.

解决方案

LocalStorage supports only string values, not boolean or others.

Method to store and retrieve values:

Put the value into storage

localStorage.setItem('value1', 'true');

Retrieve the value from storage

var val1 = localStorage.getItem('value1');

Read more on MDN..

这篇关于localStorage不支持谷歌浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆