Javascript: localStorage.getItem(key) not working
Date : March 29 2020, 07:55 AM
will be helpful for those in need You cannot store objects in localstorage directly. A workaround can be to stringify your object before storing it, and later parse it when you retrieve it: var name = { 'first': 1, 'second': 2, 'third': 3 };
// Put the object into storage
localStorage.setItem('name', JSON.stringify(name));
// Retrieve the object from storage
var retrievedObject = JSON.parse(localStorage.getItem('name'));
|
Javascript / jQuery with localStorage API not working
Date : March 29 2020, 07:55 AM
should help you out after looking at your gist link, I found that guestEmail is a textbox on your page so the innerHTML is not going to work here. also the jquery implementation for both .value and .html is not correct. you need to update your jquery as follows $(function() {
// Check for LocalStorage support.
if (localStorage) {
// Add an event listener for form submissions
$('form').on('submit', function() {
// Get the value of the email field.
var email = $('#email').val();
// Save the name in localStorage.
localStorage.setItem('#email', email);
$('#guestEmail').html(email);
console.log(localStorage.getItem('#email'));
});
}
var emailLocalStorage = localStorage.getItem('#email');
console.log(emailLocalStorage);
if (typeof emailLocalStorage != "undefined" && emailLocalStorage != "null") {
$('#guestEmail').val(emailLocalStorage);
console.log(emailLocalStorage)
} else {
$('#guestEmail').val("");
}
});
|
localStorage is not working in JavaScript
Date : March 29 2020, 07:55 AM
wish of those help Your code does appear to work. If you console.log(JSON.parse(localStorageItems)) right above line 49 in the loadFromLocalStorage function, it shows as expected in the console. Also, upon refreshing the items persist. If what you mean is that you're checking localStorage and you don't see the items, it might be that you're looking at the preview version of localStorage. (I'm assuming you're using Chrome.) Hover over the top of the empty section and pull down, this should reveal the values stored. If you click on one, it should show in the preview section. I think this was a Chrome dev tools UI change recently implemented.
|
Javascript Slideshow not working when using LocalStorage
Date : March 29 2020, 07:55 AM
wish helps you I think the issue is that you need to convert string to number before you operate with it. The value retrieved from localStorage is always of a String type, while you expect number in your code. Try this: var slideIx = Number(localStorage.getItem('slideIndex') || 1);
|
How to get localStorage in Javascript working in Firefox 71.0
Date : September 23 2020, 12:00 AM
this one helps. You don't set localStorage.getItem("first_name"); to a variable. Instead, your code should look like this: var first_name = localStorage.getItem("first_name");
console.log("fn",first_name);
|