入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

ios 中 localstorage有时失效的问题

创建时间:2017-08-04 投稿人: 浏览次数:131

        ios中 由子页面setItem值,history.back返回主页面,有时会get不到item值,查询外文资料知道 localstory值仍然是存在的,但是setItem会报异常 quotaExceededError,所以在返回主页面后getItem和removeItem会被忽略。

       针对以上问题  我们可以用store.js来解决。store.js 是一个兼容所有浏览器的 LocalStorage 包装器,不需要借助 Cookie 或者 Flash。store.js 会根据浏览器自动选择使用 localStorage、globalStorage 或者 userData 来实现本地存储功能

      使用方法与localstory一致

     store.set("username", "marcus") 

     store.get("username") 
     store.remove("username") 
     store.clear() 

     顺便写出判断是否支持localstory方法

function isLocalStorageSupported() {

var testKey = "test",

storage = window.sessionStorage;

try {storage.setItem(testKey, "testValue");

storage.removeItem(testKey);

return true;}

catch (error)

{return false;}}

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像