【问题标题】:Localstorage not working on android本地存储无法在安卓上运行
【发布时间】:2014-07-18 18:15:58
【问题描述】:

我在运行 JQM 的 android 设备上运行 localstorage 时遇到了一个奇怪的问题。 我应该提一下,当在网络浏览器上查看时,我的代码工作得非常好,但是在我的 android 上,它不会从 localStorage.getItem('visittime') 接收变量。

脚本基本上是我自己的小弹出窗口,每分钟向用户显示一次。 我使用当前时间戳将变量存储在本地存储中。如果变量存在,它将与现在的时间戳进行比较。如果超过一分钟,pop 将再次显示。

$( document ).on( "pagecreate", function() {
    var now = new Date().getTime(),
        storagedate = localStorage.getItem('visittime');
    if(storagedate){
        var diff = now - storagedate;
        if(diff > 60000){
            localStorage.removeItem('visited');
            localStorage.removeItem('visittime');
        }
    }
    var yetVisited = localStorage.getItem('visited');
    if (!yetVisited) {
        $(".welcomewindow").delay(1500).fadeIn("300", function(){
            $(".welcome").css({"margin-left":leftPos,"width":welcomeSetwidth}).fadeIn("300") ;
        });
        $(".welcomeClose").on("click",function(e){
            $(".welcomeshield").fadeOut("300");
            $(".welcome").fadeOut("300");
            localStorage.setItem('visited','yes');
            localStorage.setItem('visittime', new Date().getTime());
        });
    }
}

我看到人们遇到了一些类似的问题,他们通过更改要在 JQM 加载之前或在 mobileinit 上调用的脚本的位置来解决它。我一直无法弄清楚这一点。

【问题讨论】:

标签: javascript android jquery jquery-mobile local-storage


【解决方案1】:

尝试使用sessionStorage.comp='12344'; 设置值 和var value= sessionStorage.comp; 得到它们

【讨论】:

  • 如何使用这个删除会话?我需要能够添加、读取和删除。
  • 关闭浏览器后即被删除。您可以将其保存在 cookie 中或使用: var test = "hello world"; localstorage.storageTest = 测试; var test2 = localstorage.storageTest;删除 localStorage.removeItem('storageTest');
  • @user3023313 他不是在谈论浏览器。他要一个移动设备。我现在有同样的问题,我想知道移动设备上是否真的存在会话或 cookie。
猜你喜欢
  • 1970-01-01
  • 2018-02-28
  • 1970-01-01
  • 2021-08-18
  • 2019-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
相关资源
最近更新 更多