Error using sessionStorage

I am trying to use sessionStorage on a page, but this gives me an error. Here is the code:

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

Error I get from firebug console: Operation not supported "code:" 9

When I try to use localStorage, it works fine, so why does sessionStorage cause an error?

+3
source share
1 answer

The only thing I can think of is that the page is not ready, try to put this code at the end

<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 does not work in "local mode", but it will work if you upload the file to the server.

+8
source

Source: https://habr.com/ru/post/1779093/


All Articles