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> 
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments