Javascript: Simple package localStorge operation

Determine whether the browser supports localStorge

Determine whether the browser is in incognito mode

Simple json encoding

 

// Storage localStorge 
function setLocalStorage(key,obj){
     if (!navigator.cookieEnabled|| typeof window.localStorage == ' undefined ' ){
         return  false ;
    }
    localStorage.setItem(key, JSON.stringify(obj));
    return  true ;
}
// Read 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);
}

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *