html - session 存储在 IE 中不起作用

标签 html session internet-explorer-10 session-storage

我正在使用以下代码来测试 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/

相关文章:

html - 对齐 HTML 表单字段 - 转换为 CSS

ruby-on-rails - Restful 认证 : Allow logins from multiple computers?

c# - 这是IE10的BUG吗? ASP .NET MVC3 + HTML5 + IE10 预览

html - SVG 内联 CSS 不显示在 Internet Explorer 中

javascript - Internet Explorer 9/10 中是否存在带有 innerHTML =""的错误?

html - CSS 背景图像仅跨度 960px

javascript - 如何在 cookie 中存储 html 表单元素?

Node.js 在数据库中保存 session 时出现错误,Sails.js 使用 sails-mongo 模块?

asp.net-mvc - 用于存储用户信息的 MVC Session 与 DB 调用

javascript - 保证始终位于网页顶部