HTML5 Storage
An HTML5 local storage wrapper that adds the ability to save and retrieve objects from local storage.
How To Use
-
Include the storage script in your project:
<html> ... ... <body> ... ... <script src="libs/html5-storage/storage.js"></script> ... ... </body> </html>
-
Use
window.storage
to access the browsers local storage:function Person(name, gender) { this.name = name; this.gender = gender; } var user = window.storage.getItem("user"); if(user === null) { user = new Person("JJ Ford", "male"); window.storage.setItem("user", user); }
-
Include attribution to library.
API
clear()
Clears browsers local storage.
getItem(key)
Retrieves the item associated with the given key from the browsers local storage.
isSupported()
Determines if the browser supports local storage.
length
Returns the size of the browsers local storage.
removeItem(key)
Removes the item associated with the given key from the browsers local storage.
setItem(key, data)
Saves the given data to the browsers local storage under the given key.