【问题标题】:Setting cookie expiration with js-cookie使用 js-cookie 设置 cookie 过期时间
【发布时间】:2016-09-21 05:13:04
【问题描述】:

我很难理解(和设置)我在网站上使用的这个 cookie 的过期时间,以触发 facnybox 弹出窗口。我的目标是让 cookie 设置一分钟。

干杯,并提前感谢您提供的任何澄清。

<script type="text/javascript">
  $(document).ready(function() {
      var check_cookie = $.cookie('index_popup');
      var inOneMin = new Date(new Date().getTime() + 1 * 60 * 1000);
      if(check_cookie == null){
        $.cookie('index_popup', { expires: inOneMin });
        //fire your fancybox here
        $.fancybox({
          maxWidth    : '100%',
          fitToView   : false,
          width       : '100%',
          height      : 'auto',
          autoSize    : false,          
          href: "#split_popup"
        });
      }
  });
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

  <div style='display:none'>
    <div id='split_popup'>
        <p>cool stuff here<p>      
  	</div>      
  </div>  

【问题讨论】:

    标签: javascript jquery cookies popup js-cookie


    【解决方案1】:

    您可以这样做;首先你必须设置你的cookie:

    Cookie.set('yourCookieName', 'itsValue');

    要设置到期日期,文档说:

    创建一个在 7 天后过期的 cookie,在整个网站上有效: Cookies.set('name', 'value', { expires: 7 });

    要获取 cookie 的值,只需使用 js-cookie 提供的 get 方法: Cookies.get('name'); 结果itsValue

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-17
      • 1970-01-01
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 2017-01-11
      相关资源
      最近更新 更多