This is my first time working with localStorage, and I’m trying to store a json object which I am stringify(ing).
On my home page, I use the following code
localStorage.setItem("users",JSON.stringify(userList));
alert(localStorage.getItem("users"));
location.href="test2.html";
This alert spits out the userlist no problem.
Then on the test2.html, I have
var userList=JSON.parse(localStorage.getItem("users"));
alert(userList.toSource());
Firebug spits out a ‘userlist is null’ error.
I’ve tried using the string ‘test’ in place of the strigified json object, but no luck. I’ve also tried removing the JSON.parse and just get the string returned. This also didn’t work.
What am I doing wrong??
Modern browsers have decided that local files (“file://” URLs, in other words) are not all to be considered members of a common “domain”, at least for some purposes. Chrome seems to be the strictest, but maybe in the HTML5 features Firefox is also as strict.
It kind-of makes sense: if somebody invents some kind of TiddlyWiki-like tool that uses HTML5 storage, you wouldn’t want its stuff to be available to some random other HTML file you download for totally unrelated reasons.