/ Published in: JavaScript
logs values for local/session storage if supported
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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);