2

我正在使用HTML 5项目模板制作Windows 8 Phone应用程序。localStorage不能使用IE 10投掷错误

我有下载jQuery的1.9.1.js使用的NuGet也已经下载jquery.mobile-1.2.0.js从here并将它们添加到我的项目。

现在,我使用下面的代码,我试图用localStorage,我下面的代码与Chrome和Firefox,但与IE 10

Common.js

$(document).ready(function(){ 
    alert("jquery started"); 
    localStorage.selectedCategory = "cc"; 
    alert("After assignment"); 
    alert(localStorage.selectedCategory); 
}) 

当我在IE 10中运行这个时,我在控制台中得到以下错误消息,并且只显示了我的第一条警报“jquery started”,其余警报未显示。

SCRIPT5007:无法获取未定义或空引用 jquery.mobile-1.2.0.js,线2536字符的属性 'MSIE' 5

SCRIPT5007:无法设置的未定义的属性 'selectedCategory'或空引用 common.js,第3行字符2

enter image description here

目前我注释掉localStorage的代码,所有警报被示出,但仍然是控制台中的错误之一。

SCRIPT5007:无法获取未定义或空引用 jquery.mobile-1.2.0.js,行2536字符5

enter image description here

我只是似乎没有的特性 'MSIE'要了解这个问题,请帮我解决这个问题。

编辑: 我的html代码:

<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <link rel="stylesheet" type="text/css" href="/html/css/phone.css" /> 
     <title>Interview QA</title> 
     <script type="text/javascript" src="../Scripts/jquery-1.9.1.js"></script> 
     <script type="text/javascript" src="../Scripts/jquery.mobile-1.2.0.js"></script> 
     <script type="text/javascript" src="../Scripts/Custom/common.js"></script> 
    </head> 
    <body> 
     <div id="header"></div> 
     <div id="footer"></div> 
     <div></div> 
    </body> 
</html> 
+1

是不是你的帖子在这里重复:http://stackoverflow.com/questions/14795286/localstorage-not-working-with-windows-8-phone-html-5-project-template – 2013-02-16 05:20:50

回答

2

你可能需要正确的文档类型:

<!doctype html> 
+0

是我我正在使用它。我用我正在使用的html更新了我的问题;请看一看。谢谢 – Yasser 2013-02-16 05:20:07

+0

看看hexacyanide的答案 - 这对你来说可能是正确的。 – 2013-02-16 05:20:41

+0

是的,那确实解决了我的第二个问题。但使用localStorage时仍会出现相同的错误。如何解决这个问题? – Yasser 2013-02-16 05:23:43

2

我也得到了同样的错误。但是,当我用关键字“Storage”替换“localStorage”时,它在ie10中起作用。修改你的代码是这样,尝试:

$(document).ready(function(){ 
    alert("jquery started"); 
    Storage.selectedCategory = "cc"; 
    alert("After assignment"); 
    alert(Storage.selectedCategory); }) 

更新:但是,这并不等同于本地存储,因为刷新页面时,此清关。进一步研究发现localStorage在ie10中与file://协议不起作用。但是,如果您将您的页面托管在Web服务器(IIS/Tomcat等)下,)并通过http://协议访问它,localStorage在ie10中工作得很好。