I'm trying to do a mega-simple setItem and getItem using HTML5 local storage. It just doesn't seem to work though. This works:
$(document).ready(function () {
localStorage.setItem('keyA', 'valueA');
var testA = localStorage.getItem('keyA');
alert(testA);
});
It outputs an alert box saying 'valueA'. But when I comment out line 2 (which sets the item value) and refresh the page it just alerts 'null'.
Why is the value not persisting? It's like it's just not actually getting stored at all.
The browser is Firefox 6, so no problem there. Could it be something to do with calling it in the jquery document.ready? I've googled but couldn't see anything about that.
If anyone could get me over this initial hurdle I'd be most grateful, thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…