Press "Enter" to skip to content

HTML5-Local Storage Examples

Last updated on October 4, 2019

Definition :

      Local storage is an object which is meant for which holds the data till the web pages refreshed.

Program 1 :

<html>

   <body>

      <div id=”result”> </div>

                     <script>

                                   if(typeof(Storage)!==”undefined”){

                                   localStorage.setItem(“lastname”,”testing”);

                                   document.getElementById(“result”).innerHTML=localStorage.getItem(“lastname”);

                                   }else{

                                   document.getElementById(“result”).innerHTML=”sorry,your browserdoes not support web storage…”;

                                   }

                                 </script>

                </body>

</html>              

Program 2 :

<html>

     <script>

                     a=1;

                                   function display()

                                   {

                                     if(typeof(Storage) !=”undefined”) {

                                                 localStorage.setItem(“lastname”, a++);

                                                 document.getElementById(“result”).innerHTML=localstorage.getItem(“lastname”);

                                                 } else {

                                                 document.getElementById(“result”).innerHTML”sorry, your browser does not support web storage…”;

                                                 }

                                                 }

                </script>

                <body>

                     <button onclick=”display()”> click me </button>

                                 <div id=”result”> </div>

                </body>

</html>

Be First to Comment

    Leave a Reply

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