HTML and CSS Reference
In-Depth Information
TABLE 1-13 Methods available on storage objects
Method
Description
Adds a key/value pair into storage. If no item with the specified key exists, the item is
added; if that key does exist, its value is updated.
setItem
Retrieves data from storage based on a specified key value or index.
getItem
Clears all storage that has been saved. Use this method to clear out the storage as
needed.
clear
Retrieves the key at a specified index. You can use the resultant key to pass as a
parameter to one of the other methods that accepts a key.
key
Removes the specified key/value pair from storage.
removeItem
In addition to the methods described in Table 1-13, the storage objects expose a length
property which returns the number of key/value pairs in storage. Use the sample code in
Listing 1-4 to explore the Web Storage API.
LISTING 1-4 Exploring the Web Storage API
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title></title>
<style>
section {
margin-top: 15px;
}
</style>
<script>
window.onload = function () {
document.getElementById("btnAdd").onclick = function () {
}
document.getElementById("btnRemove").onclick = function () {
}
document.getElementById("btnClear").onclick = function () {
}
function LoadFromStorage() {
}
}
</script>
</head>
<body>
<section>
Key:
<input type="text" id="toStorageKey"/>
Value:
<input type="text" id="toStorageValue"/><br/>
</section>
 
Search WWH ::




Custom Search