2013-04-25 92 views
6

我正在使用以下代码来测试HTML 5的会话存储空间。它在所有除IE以外的浏览器中工作正常。安装了IE浏览器的版本是10会话存储在IE中不工作

代码:

<!DOCTYPE html> 
<html> 
<head> 
<script> 
function clickCounter() 
{ 
if(typeof(Storage)!=="undefined") 
    { 
    if (sessionStorage.clickcount) 
    { 
    sessionStorage.clickcount=Number(sessionStorage.clickcount)+1; 
    } 
    else 
    { 
    sessionStorage.clickcount=1; 
    } 
    document.getElementById("result").innerHTML="You have clicked the button " + sessionStorage.clickcount + " time(s) in this session."; 
    } 
else 
    { 
    document.getElementById("result").innerHTML="Sorry, your browser does not support web storage..."; 
    } 
} 
</script> 
</head> 
<body> 
<p><button onclick="clickCounter()" type="button">Click me!</button></p> 
<div id="result"></div> 
<p>Click the button to see the counter increase.</p> 
<p>Close the browser tab (or window), and try again, and the counter is reset.</p> 
</body> 
</html> 

可能是什么问题呢?

+0

它是一个计数器,每增加一次e用户点击“点击我”按钮 – 2013-04-25 11:00:21

+0

它显示脚本错误,因为在if(sessionStorage.clickcount)条件中的未定义引用只在IE中,就像你说的 – Arun 2013-04-25 11:06:19

+0

是的,即使在会话存储中设置它后它不工作。 – 2013-04-25 11:14:32

回答

17

我发现HTML5的本地存储和会话存储功能是,只有当页面通过HTTP呈现时,这两个功能才能在Internet Explorer中正常工作,并且在尝试访问这些功能时不起作用在你的本地文件系统,即你正在尝试直接从与各种各样的URL,C:/Users/Mitaksh/Desktop等文件系统打开示例网页..

部署在任何application serverTomcat,等你的应用程序,然后访问它。 。你可以在行动中看到本地和会话存储。然后..

+2

如果使用Phonegap从包含本地存储或会话存储的代码创建应用程序,并且该应用程序在使用IE的设备上运行,结果会是什么? – user2662157 2013-11-16 17:02:59