The localStorage object stores the data with no time limit. It can store upto 5MB of data locally on a user device in a key-value database inside a web browser.
Below shows a simple example for storing and retrieving data in local storage.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function loc() {
var name = document.getElementById("txt1").value;
localStorage.setItem(name, "aaa");
document.getElementById("txt2").value = localStorage.getItem(name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="txt1" />
<br />
<input type="text" id="txt2" />
<input type="button" id="btn1" value="submit" onclick="loc();" />
</div>
</form>
</body>
</html>
Posted by:
CS1401
on: 8/10/2011
Level:Starter | Status: [Member] | Points: 10
hey what is the difference of normal html coding and this coding. why you specify this code belongs to html 5.can u explain?
Hi,
Here I'm showing the localStorage feature of HTML5 (See how data is stored in localStorage object in the above code).
The above javascript code is worked only in those browsers which support HTML5. Using localStorage we can store upto 5MB of data locally(without cookies,session etc).
Posted by:
CS1401
on: 8/11/2011
Level:Starter | Status: [Member] | Points: 10
oh thankx nitha.. its sounds good.. keep it up.