error using sessionStorage

北慕城南 提交于 2019-12-10 19:04:50

问题


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 sessionStorage cause an error?


回答1:


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.



来源:https://stackoverflow.com/questions/4383494/error-using-sessionstorage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!