我正在使用以下代码来测试 HTML 5 的 session 存储。它在除 IE 之外的所有浏览器中都运行良好。安装的IE版本是10。
代码:
<!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>
可能是什么问题?
最佳答案
我对 HTML5 的本地存储和 session 存储功能的发现是,只有当页面通过 HTTP
呈现时,这两个功能才能在 Internet Explorer 中工作,而当您正在尝试在您的本地文件系统上访问这些功能,即您正在尝试使用各种 URL 等直接从文件系统打开示例网页,C:/Users/Mitaksh/Desktop
等。
将您的应用程序部署到任何应用程序服务器
(例如Tomcat
等)上,然后访问它。然后您可以看到本地和 session 存储正在运行。
关于html - session 存储在 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16212347/