Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use HTML5 Local Storage

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 280
    Comment on it

    HTML5 Local Storage(Web Storage) mechanisms provides you the facility to store data much more easy way than cookies. Local storage save the data more secure then cookies, where cookie only can store data up to 5mb, local storage capacity is far larger than cookie.

    In local storage you can set data with no expiration date, so if you close your browser and come next time your data will not be deleted.

    Local data storage data is saved in key/value pair.

    // Store data 
    localStorage.setItem("it_company", "Evon");
    

    Lets try an example to save JSON array in local storage and receive the object from local storage.

    var myObject = { 'color': 'red', 'name': 'prabhat', 'city': 'dehradun' };
    
    // Put the object into storage
    localStorage.setItem('savedObject', JSON.stringify(myObject));  //save data in local storage
    
    // Retrieve the object from storage
    var retrievedObject = localStorage.getItem('savedObject');   //retrieve data from local storage
    
    console.log('retrievedObject: ', JSON.parse(retrievedObject));
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: