[javascript] 简单封装localStorge操作
作者:互联网
判断浏览器是否支持localStorge
判断浏览器是否为无痕模式
简单的json 编码
//存储localStorge function setLocalStorage(key,obj){ if(!navigator.cookieEnabled||typeof window.localStorage == 'undefined'){ return false; } localStorage.setItem(key, JSON.stringify(obj)); return true; } //读取localStorge function getLocalStorage(key){ if(!navigator.cookieEnabled||typeof window.localStorage == 'undefined'){ return false; } var str=localStorage.getItem(key); if(!str){ return false; } return JSON.parse(str); }
标签:return,str,localStorge,javascript,localStorage,key,封装,false 来源: https://blog.51cto.com/u_15274085/2918179