这工作完全在Chrome和Firefox:为什么localStorage.getItem仅在IE9中失败?
var webStorageSupported = ('localStorage' in window) && window['localStorage'] !== null;
if (webStorageSupported && localStorage.getItem("get_list_center") !== null) {
document.getElementById('mail_listing').innerHTML = localStorage.getItem("get_list_center");
}
,但我得到一个未知的例外,当我在IE9
查看页面。如果我在控制台中单独键入:document.getElementById('mail_listing').innerHTML;
和localStorage.getItem("get_list_center");
,我能够获得本地存储中的元素和内容。
当我尝试分配innerHTML
作为本地存储,发生未知异常。是什么赋予了???
编辑:根据评论的建议,我试图让本地存储在一个单独的变量,然后在innerhtml中分配该变量。原来,localStorage的确实检索HTML格式的代码,但它无法保存整个字符串:
<table width="100%">......
<TD width=\"7%\" align=right>12K </TD></TR></TBODY></TABLE></DIV>\r\n<DIV style=\"DISPLAY: no
[[CUT OFF FROM HERE]]
我的印象是,localStorage的节省了高达5 MB的文本,这是案件对于Chrome和Firefox,但也许这不是IE9的情况(编辑:谷歌搜索后,IE9 supports up to 10MB显然是另一回事)。我能做些什么来解决这个问题?
EDIT2:我已经验证,如果检索后权的内容已被设置localStorage的正确分配整个HTML内容:
localStorage.setItem('get_list_center', document.body.innerHTML);
var x = localStorage.getItem('get_list_center'); //GETS THE WHOLE HTML CONTENT CORRECTLY.
只是,当我正从某处内容否则我需要它的内容会被切断。本地存储不会在其他地方被篡改。
您是否尝试过使用中间变量?在您的实际代码中使用console.log来验证每个步骤? – 2013-02-22 09:09:59