HTML5, localStorage

In this example, the page will load first without the text stored by HTML5. On refresh you will see the text: “The text you want to save”, appear in the <div> container.


<!DOCTYPE html>
<html>
<head>
   <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
</head>
<body>
   <header>Storing Items using HTML5</header>
   <div id="show">Text Stored: </div>
   <script>
      if(localStorage.getItem("varContainer")) {
      $("#show").append(localStorage.getItem("varContainer"));
      }
   localStorage.setItem("varContainer", "The text you want to save");
</script>
</body>
</html>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s