使用sessionStorage时出错 [英] error using sessionStorage

查看:172
本文介绍了使用sessionStorage时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在页面上使用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>

我从firebug控制台获得的错误是:不支持操作code:9

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

当我尝试使用localStorage它工作正常时,为什么sessionStorage会导致错误?

When I try to use localStorage it works fine, so why does sessionStorage 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>

最终答案:
sessionStorage无法在本地模式下工作,但如果您将文件上传到服务器,它将起作用。

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

这篇关于使用sessionStorage时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆