How To Use Local Storage

Local Storage, web applications can store user browsing data locally. Local storage can store large quantities of data locally, Cloud Storage, use as multiple language and currency etc. Now I’m demonstrating how Local Storage data can be set and receive.

In this example you can click on button and store input box data in Local Storage.

Example


<div>
	Web Storage example:
	<br />
	<div id="divDataLocalStorage"></div>
	<br />
	Value
	<input type="text" id="txtboxFooExampleLocalStorage" />
	<input type="button" id="SaveToLocalStorage" value="Save Text to Local Storage" />
</div> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
 
  <script type="text/javascript">
 
    RetrieveFromLocalStorage();
 
    $("#SaveToLocalStorage").click(function () 
    {
      alert('sdf');
       var txtboxFooValue = $("#txtboxFooExampleLocalStorage").val();
       localStorage.setItem('LocalStorageKey', txtboxFooValue);
       RetrieveFromLocalStorage();
    });
 
      function RetrieveFromLocalStorage() 
      {
        var retrivedValue = 'None';
        var retrivedValue = localStorage.getItem('LocalStorageKey', retrivedValue);
        $("#divDataLocalStorage").text(retrivedValue);
   
    }
    </script> 

Leave a Reply

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