开发者

error using sessionStorage

I am trying to use sessionStorage on a page but it is giving me an error. Here is the code:

<script type="text/JavaScript">
 sessionStorage.setItem("classname", "value1");
 sessionStorage.setItem("classdesc", "value2");
</script>

The error I get from firebug console is: Operation is not supported" code: "9

When I try to use localStorage it works fine, so why does sess开发者_如何学CionStorage cause an error?


The only thing I can think of is that "the page isn't ready", try placing this code at the end of the body section

<html>
  <head></head>
  <body>
    <!-- YOUR PAGE HERE -->
    <script type="text/JavaScript">
      sessionStorage.setItem("classname", "value1");
      sessionStorage.setItem("classdesc", "value2");
    </script>
  </body>
</html>

Final Answer: sessionStorage wont work in "local mode", but it will work if you upload the file to a server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜