session storage not working in IE
Asked Answered
P

1

7

I am using the following code to test session storage of HTML 5.. It is working fine in all the browser except IE. The IE version installed is 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?

Pam answered 25/4, 2013 at 10:28 Comment(6)
it is a counter that is incremented every time the user clicks the "click me" buttonPam
It shows script error due to undefined referrence in the if (sessionStorage.clickcount) condition only in IE just like you saidInebriant
yeah even after setting it in the session storage it is not working.Pam
I'd suggest you look into MSDN for more details .. w3schools example on session storage is returning the same error .Inebriant
It is mentioned in MSDN to access it as "window.sessionStorage" but that isn't working too.Pam
It works for me in IE10 jsfiddle.net/yPZWN/1Anklebone
P
18

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, i.e. you are trying to open the sample webpage directly from the filesystem with the URL of the sorts, C:/Users/Mitaksh/Desktop , etc..

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

Pam answered 26/4, 2013 at 5:2 Comment(1)
If an app is created using Phonegap from code that incorporates local storage or session storage, and that app is run on a device that is using IE, what will be the result?Brass

© 2022 - 2024 — McMap. All rights reserved.