我在我的JS应用程序中使用localStorage,想知道为什么IE9声称localStorage == undefined
。据我所知,IE8支持它,有没有办法使它在新版本中工作?
我在我的JS应用程序中使用localStorage,想知道为什么IE9声称localStorage == undefined
。据我所知,IE8支持它,有没有办法使它在新版本中工作?
您是在本地HTML文件上进行测试吗?即file:///
URL?
localStorage仅适用于HTTP网站。 在IE9 Dev Preview中没有改变。
IE 11可以使用
您只需要将file://127.0.0.1添加到安全选项卡下的受信任区域中(注意:确保未选中https复选框),并将此行添加到脚本顶部,根据您的代码情况可能不需要添加,除非遇到无法连接到互联网的情况。
!localStorage && (l = location, p = l.pathname.replace(/(^..)(:)/, "$1$$"), (l.href = l.protocol + "//127.0.0.1" + p));
if (typeof(Storage) != "undefined") {
// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
alert(localStorage.getItem("lastname"));
} else {
alert("Sorry, your browser does not support Web Storage...");
}
if (!localStorage) { .... }
)。 - webketje尝试用以下方式打开文件
file://127.0.0.1/c$/pathtofile/file.html
file://127.0.0.1
添加到受信任站点列表中,它就能够正常工作。 - grammar31file://127.0.0.1/...
访问本地文件。我已将file://127.0.0.1
添加到IE受信任站点列表中。 - Daryl McCullough
file://
协议进行测试吗? - Alex JasminlocalStorage
对我有效。 - Alex Jasmin