jjNford / html5-storage

Wrapper that takes advantage of the power provided by HTML5 localStorage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTML5 Storage

An HTML5 local storage wrapper that adds the ability to save and retrieve objects from local storage.

How To Use

  1. Include the storage script in your project:

    <html>
    ...
    ...
    <body>
    	...
    	...
    	
    	<script src="libs/html5-storage/storage.js"></script>
    	
    	...
    	...
    </body>
    </html>
  2. 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);
    }
  3. 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.

About

Wrapper that takes advantage of the power provided by HTML5 localStorage

License:Other


Languages

Language:JavaScript 100.0%