THE PAST, PRESENT & FUTURE OF LOCAL STORAGE FOR WEB APPLICATIONS
HTML5 storage - it’s a way for web pages to store named key/value pairs locally, within the client web browser. Like cookies, this data persists even after you navigate away from the web site, close your browser tab, exit your browser, or what have you.
type | description |
---|---|
setItem() | with a named key that already exists will silently overwrite the previous value. |
removeItem() | methods for removing the value for a given named key |
key() |
You can trap the storage event. The storage event is fired on the window object whenever
setItem(), removeItem(), or clear()
is called and actually changes something.
if (window.addEventListener) {
window.addEventListener("storage", handle_storage, false);
} else {
window.attachEvent("onstorage", handle_storage);
};
The handle_storage callback function will be called with a StorageEvent object, except in Internet Explorer where the event object is stored in window.event.
function handle_storage(e) {
if (!e) { e = window.event; }
}
At this point, the variable e will be a StorageEvent object, which has the following useful properties.
5 megabytes
-is how much storage space each origin gets by default.QUOTA_EXCEEDED_ERR
-is the exception that will get thrown if you exceed your storage quota of 5 megabytes.no
- is the answer to the next obvious question, “Can I ask the user for more storage space?Data is stored as a string.