【问题标题】:session storage not working in IE会话存储在 IE 中不起作用
【发布时间】:2015-08-12 20:33:03
【问题描述】:

我正在使用以下代码来测试 HTML 5 的会话存储。它在除 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>

可能是什么问题?

【问题讨论】:

  • 这是一个计数器,每次用户点击“点击我”按钮时都会递增
  • 它显示脚本错误由于 if (sessionStorage.clickcount) 条件中未定义的引用,仅在 IE 中,就像你说的那样
  • 是的,即使在会话存储中设置后它也无法正常工作。
  • 我建议您查看 MSDN 了解更多详细信息 .. w3schools 关于会话存储的示例返回相同的错误。
  • 在 MSDN 中提到以“window.sessionStorage”的形式访问它,但这也不起作用。

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


【解决方案1】:

我发现 HTML5 的本地存储和会话存储特性是,这两个特性只有在页面通过 HTTP 呈现时才能在 Internet Explorer 中工作,而当您尝试访问这些特性时将无法工作本地文件系统上的功能,即您尝试使用各种 URL 直接从文件系统打开示例网页,C:/Users/Mitaksh/Desktop 等。

在任何application server 上部署您的应用程序,例如Tomcat 等,然后访问它......然后您可以看到本地和会话存储在运行中......

【讨论】:

  • 如果一个应用是使用 Phonegap 从包含本地存储或会话存储的代码创建的,并且该应用在使用 IE 的设备上运行,结果会是什么?
猜你喜欢
  • 2014-02-02
  • 2015-04-29
  • 1970-01-01
  • 1970-01-01
  • 2014-03-14
  • 2016-08-07
  • 1970-01-01
  • 2010-12-10
  • 2018-08-03
相关资源
最近更新 更多