1

当我重新加载相同页面时,我无法在Firefox 4 Web浏览器中检索本地存储值。支持两种浏览器(Chrome和Firefox)的javascript本地存储

注意:下面的代码在谷歌最新的Chrome网络浏览器工作正常

我的代码:

//Set item 
var bookmark_value = document.getElementById('bookmark').value; 
var storageIndex = "Bookmarked_Page_" + i;    
localStorage[storageIndex] = bookmark_value; 

//get item 
document.bookmark["bookmark"].value = localStorage["Bookmarked_Page_" + i]; 
+1

'document.bookmark'是不确定的。 – Raynos 2011-04-13 15:30:33

+0

我只是在文本框中获取本地存储项目。 – user706339 2011-04-13 15:33:18

+0

[IE中的本地存储]的可能重复(http://stackoverflow.com/questions/5660216/local-storage-in-ie)。这看起来一样。你能解释为什么@Darin Dimitrov对这个问题的回答不够充分。 – 2011-04-14 08:04:11

回答

2

你不应该依赖于浏览器添加具有直接的ID元素到document

//get item 
document.getElementById('bookmark').value = localStorage["Bookmarked_Page_" + i]; 
0

错字?

document.bookmark["bookmark"].value 

应该

document.getElementById('bookmark').value 

编辑

哦,我想是你的问题,看看这个问题,回答:Is "localStorage" in Firefox only working when the page is online?

+0

雅,你是对的..我的查询是:本地存储值被清除,当我重新加载页面在firefox4 ..你能请指导我 – user706339 2011-04-13 15:39:12

+0

仅供参考:我执行文件中的示例模块:///(URL)。 – user706339 2011-04-13 15:44:43

+0

嗨..我现在已经解决了这个问题..我想分享这个想法给你,我只是在xampp服务器中移动了html文件..并且我将ulr发送到http://localhost/$filename.html ..谢谢 – user706339 2011-04-13 16:02:13

相关问题