Local storage in javascript that supports both browsers (Chrome and Firefox)
I was not able to retrieve my local storage values in Firefox 4 web browser when i reloaded the same page.
Note: The code below is working fine in the latest Google Chrome web browser
My code:
//Set item
var bookmark_value = document.getElementById('bookmark').value;
var storageI开发者_运维知识库ndex = "Bookmarked_Page_" + i;
localStorage[storageIndex] = bookmark_value;
//get item
document.bookmark["bookmark"].value = localStorage["Bookmarked_Page_" + i];
You shouldn't rely on the browser adding elements with an ID directly onto the document
.
//get item
document.getElementById('bookmark').value = localStorage["Bookmarked_Page_" + i];
typo?
document.bookmark["bookmark"].value
should be
document.getElementById('bookmark').value
Edit
Oh I think that's your problem, check out this question and answer: Is "localStorage" in Firefox only working when the page is online?
精彩评论