# qooxdoo

Home » Manual (v2.0.2) » qx.Website » Client-side Storage

# Client-side Storage

Note

This document is outdated and does not reflect the proposed way of working with qx.Website. The storage module is still under development. As soon as the module is ready, this document will be updated as well.

A universal cross-browser storage API exists that offers client-side key-value pair storage. Most of the modern browsers support the WebStorage API. There also is a fallback implementation for IEs below version 8 based on userData. For all other runtimes, a fallback exists in the form of an in-memory storage. While the latter means you don't store the data in a persistent way, you still have the benefit of using the same API to access the storage.

## API

The API is closely aligned with the native WebStorage API and offers some convenience on top of that. The main class for you to use is `qx.bom.Storage` and comes with three different implementation classes, one for each of the three implementations mentioned. Those implementations can be found in the `qx.bom.storage` namespace.

### Basic Usage

To get an idea of the basic API please have a look at the API docs, the MDC page or the W3C specification.

### Convenience on top

We added an `forEach` method, which can be used to execute a function for every stored item.

    var storage = qx.bom.Storage.getLocal();
    storage.forEach(function(key, value) {
      // ... do whatever you want
    });

## Simple example

Here is a simple example: a counter that keeps track of how often you visited the page.

    // get the local storage object
    var storage = qx.bom.Storage.getLocal();
    // load the number and parse it
    var number = parseInt(storage.getItem("my-number-name"), 10) || 0;
    // increment the number by one
    number++;
    // write back the number
    storage.setItem("my-number-name", number);