Return to Snippet

Revision: 61152
at November 30, 2012 12:20 by zfisic


Initial Code
var output = "LOCALSTORAGE DATA:\n------------------------------------\n";
if (localStorage) {
    if (localStorage.length) {
       for (var i = 0; i < localStorage.length; i++) {
           output += localStorage.key(i) + ': ' + localStorage.getItem(localStorage.key(i)) + '\n';
       }
    } else {
       output += 'There is no data stored for this domain.' + '\n';
    }
} else {
    output += 'Your browser does not support local storage. + '\n';
}
output += "SESSIONSTORAGE DATA:\n-------------------------------------\n";
if (sessionStorage) {
    if (sessionStorage.length) {
       for (var i = 0; i < sessionStorage.length; i++) {
           output += sessionStorage.key(i) + ': ' + sessionStorage.getItem(sessionStorage.key(i)) + '\n';
       }
    } else {
       output += 'There is no data stored for this page.' + '\n';
    }
} else {
    output += 'Your browser does not support session storage.' + '\n';
}
console.log(output);

Initial URL

                                

Initial Description
logs values for local/session storage if supported

Initial Title
Log Local and Session Storage in Console

Initial Tags

                                

Initial Language
JavaScript