+ 3
Fill in the blanks to clear all values stored in the localStorage. Then store "a" using the key "b"?
localStorage.clear (); localStorage. setItem("a" , "b" ); The top is my code why does it not work?
10 Antworten
+ 4
I got the answer it is
localStorage.clear ();
localStorage.
setItem("b" , "a" );
Why is it "b" before "a" I thought the order did not matter since it did not state it in the question.
+ 4
Parameters of setItem() function have an important order:
localStorage.setItem(key,value);
So, when you getItem():
value=localStorage.getItem(key);
However, this isn't the reason for the code don't work...
I suppose you have tested it in code playground, isn't it? Because I have tested in code playground ( tablet, android, chrome ), where an exception is raised, then in "real" situation ( means in local, desktop, firefox ), where all is alright ^^
I deduce that there is a problem with how code playground manage, or with the localstorage on android/chrome... but anyway in your code :)
+ 3
More probably a question of authorization: localstorage, by definition, is local relative to the client side ( user ), not to the server side ^^
+ 2
You must see the order of the arguments of the function before use it
+ 2
Yes, still... I'll test in browsers ( desktop and android: I haven't precised that I was use the app ^^ )
+ 2
There's no problem with browser android, so the problem's only on the app... probably an authorization in android!
The error message:
"Serrurity Error not detected: Failed to read the 'localStorage' property in 'Window': Access is denied for this document."
0
Maybe there is no localStorage on playground
0
It's relative to the navigator. Are you still having problem using localStorage in playground?
0
Must be a problem with permissions in app.
Mobile devices are more problematic than browsers ever ^^
0
This is because the data is stored in key/value pairs: with the pair having the key as the initial entry. The question had stated the need to use the key "b" to store the value "a".