Localstorage没有在android上工作

时间:2014-07-18 18:15:59

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

我有一个奇怪的问题,让localstorage在运行JQM的Android设备上工作。 我应该提一下,我的代码在Web浏览器上查看时效果很好,但是在我的android上它不会从localStorage.getItem('visittime')接收变量。

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

$( 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上更改要调用的脚本的位置来解决它。我无法弄清楚这一点。

1 个答案:

答案 0 :(得分:0)

尝试使用sessionStorage.comp='12344';设置值 和var value= sessionStorage.comp;来获取它们

相关问题