简体   繁体   English

会话存储在IE中不起作用

[英]session storage not working in IE

I am using the following code to test session storage of HTML 5.. It is working fine in all the browser except IE. 我使用以下代码来测试HTML 5的会话存储。它在除IE之外的所有浏览器中都能正常工作。 The IE version installed is 10. 安装的IE版本是10。

Code : 代码:

<!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>

What could be the problem? 可能是什么问题呢?

What I found with both local storage and session storage features of HTML5 is that, that both these features will work in Internet Explorer ONLY when the page is rendered through HTTP , and will not work when you are trying to access these features on your local filesystem, ie you are trying to open the sample webpage directly from the filesystem with the URL of the sorts, C:/Users/Mitaksh/Desktop , etc.. 我在HTML5的本地存储和会话存储功能中发现的是,这两个功能只有在通过HTTP呈现页面时才能在Internet Explorer中工作,并且当您尝试在本地文件系统上访问这些功能时不起作用,即您试图直接从文件系统打开示例网页,其中包含C:/Users/Mitaksh/Desktop的URL, C:/Users/Mitaksh/Desktop等。

Deploy your application over any application server like Tomcat ,etc, and then access it.. and you can see both local and session storage in action then.. 通过任何application serverTomcat等)部署应用application server ,然后访问它..然后您可以看到本地和会话存储的运行情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM