Window self Property - Window sessionStorage Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window self


The localStorage and sessionStorage properties allow to save key/value pairs in a web browser.

The sessionStorage object stores data for only one session

Return Value

A Storage object

The following code shows how to create a sessionStorage, then retrieve the value

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
function clickCounter() {/* www  . j  a v a  2s.  co m*/
    if(typeof(Storage) !== "undefined") {
        if (sessionStorage.clickcount) {
            sessionStorage.clickcount = Number(sessionStorage.clickcount)+1;
        } else {
            sessionStorage.clickcount = 1;
        document.getElementById("result").innerHTML = "You have clicked the button " + sessionStorage.clickcount + " time(s) in this session.";
    } else {
        document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
<p><button onclick="clickCounter()" type="button">Click me!</button></p>
<div id="result"></div>

Related Tutorials