Showing posts with label SessionStorage. Show all posts
Showing posts with label SessionStorage. Show all posts

Saturday, January 27, 2018

How do you store data in Local Storage?

Local Storage is supported if you use HTML. First of all you should make sure that your browser supports Local Storage. Data is stored as NAME,VALUE pairs in local storage.

You can review this post.

Let us say you want to store the string "Hi, Good Morning". You need to create a NAME \ VALUE pair, your VALUE being "Hi, Good morning" and the NAME can be anything. In the present example the NAME is "Greetings".

All you need to do is create a web page (just HTML) shown here:

Greetings.png

When you browse this page on your local IIS Server (localhost), you will see the greeting:



Tuesday, August 29, 2017

Does your browser support localStorage?

If your browser supports HTML5 then your browser supports local storage. The image below is for Microsoft Edge 15.


You can also view this HTML file (TodaysDate.html) below on your local IIS.



<html>
<body>

<div id="result"></div>

<script>
// Check browser support
if (typeof(Storage) !== "undefined") {
    // Store
    localStorage.setItem("Today", Date());
    // Retrieve
    document.getElementById("result").innerHTML = localStorage.getItem("Today");
} else {
    document.getElementById("result").innerHTML = "No browser support for localStorage";
}
</script>

</body>
</html>

If localStorage is supported then you should see the following (for today).

This also worked on IE 11 as well as Mozilla Firefox.