js/html5 Displaying local storage
16,490
Solution 1
As local storage is Object, you can go trough all it keys and get in values in simple way
for (var key in localStorage) {
console.log(key + ':' + localStorage[key]);
}
To print it to the screen you can use something like this:
var output = '';
for (var key in localStorage) {
output = output+(key + ':' +localStorage[key])+'\n';
}
$('#DivToPrintOut').html(output);
Solution 2
If you're using Chrome, press F12 for the Developers Tools.
In the Console type localStorage
and press enter.
Or in your js code put console.log(localStorage);
.
In the console, click on the little triangle next to line that begins with Storage
.
Or in Dev Tools:
- click on the
Resources
tab at the top - click on the little triangle next to
Local Storage
in the frame on the left
Author by
user1
Updated on June 14, 2022Comments
-
user1 almost 2 years
Is there a simple way to display my local storage with document.write or document.innerHTML methods? It's being stored on 1 page, trying to display on separate. I'm new to js and just unsure how to build the syntax of those methods with how I'm storing it(if possible).
$('form').submit(function() { var person = $("#FirstName").val() + "." + $('#LastName').val(); $('input, select, textarea').each(function() { var value = $(this).val(), name = $(this).attr('name'); localStorage[person + "." + name] = value; window.location.href = "Confirmation.html"; console.log('stored key: '+name+' stored value: '+value); }); });
heres the whole if it helps: http://jsfiddle.net/EUWFN/
-
user1 over 10 yearsdoes this print the localstorage to the page or just in the console?
-
Admin over 10 years@user2912336, you can print
localStorage[key]
any way you want. For example$('.someclass').html(localStorage['key_name'])
ordocument.write(localStorage['blahblah'])
. -
user1 over 10 yearswhat if these keys etc are defined on a separate page?
-
paka over 10 yearsdoes not matter on what page they was setted. Localstorage is one for all pages within one domain.
-
paka over 10 yearsdo you get eny erorrs is console?