在页面刷新时更改localstorage值

时间:2017-04-07 08:45:17

标签: javascript jquery html5 local-storage

我正在为我的html应用创建一个欢迎屏幕。我正在使用github的欢迎屏幕插件。你可以在这里查看https://github.com/valnub/welcomescreen.js

现在我想在localstorage值为0时显示欢迎屏幕。当点击welcomescreen的关闭按钮时,我将localstorage值更改为1.但是在页面刷新时,localstorage值再次设置为0.

怎么做这是我的js文件。

/*jslint browser: true*/
/*global console, Welcomescreen, $*/

// Init method

$(document).ready(function () {
  localStorage.setItem("welscreen", "0");	
  var welcomeTour = localStorage.getItem("welscreen");
	
  if (welcomeTour == 0) {

    $(document).ready(function () {     
       var options = {
            'bgcolor': '#0da6ec',
            'fontcolor': '#fff',
            'onOpened': function () {
             console.log("welcome screen opened");
	         console.log(welcomeTour);
       },
      'onClosed': function () {
          localStorage.setItem("welscreen","1");
	      var welcomeTour = localStorage.getItem("welscreen");
	      console.log("welcome screen closed");
	      console.log(welcomeTour);
        }
     },
     welcomescreen_slides,
     welcomescreen;

    welcomescreen_slides = [
      {
        id: 'slide0',
        picture: '<div class="tutorialicon">♥</div>',
        text: 'Welcome to this tutorial. In the <a class="tutorial-next-
        link" href="#">next steps</a> we will guide you through a manual that will teach you how to use this app.'
      },
      {
        id: 'slide1',
        picture: '<div class="tutorialicon">✲</div>',
        text: 'This is slide 2'
      },
      {
        id: 'slide2',
        picture: '<div class="tutorialicon">♫</div>',
        text: 'This is slide 3'
      },
      {
        id: 'slide3',
        picture: '<div class="tutorialicon">☆</div>',
        text: 'Thanks for reading! Enjoy this app or go to <a class="tutorial-previous-slide" href="#">previous slide</a>.<br><br><a class="tutorial-close-btn" href="#">End Tutorial</a>'
      }
   ];

  welcomescreen = new Welcomescreen(welcomescreen_slides, options);

  $(document).on('click', '.tutorial-close-btn', function () {
    welcomescreen.close();
  });

  $('.tutorial-open-btn').click(function () {
    welcomescreen.open();  
  });

  $(document).on('click', '.tutorial-next-link', function (e) {
    welcomescreen.next(); 
  });

    $(document).on('click', '.tutorial-previous-slide', function (e) {
       welcomescreen.previous(); 
     });      
   });
 };
});

1 个答案:

答案 0 :(得分:4)

改变这个:

item_count = 0
for item in MyModel.batch_get(id_list):
    item_count += 1

# Check the item_count

到此:

localStorage.setItem("welscreen", "0"); 
var welcomeTour = localStorage.getItem("welscreen");