Skip to content

Latest commit

 

History

History
80 lines (57 loc) · 1.25 KB

README.md

File metadata and controls

80 lines (57 loc) · 1.25 KB

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.