0

我正在努力理解(并设置)我在网站上用来触发 facnybox 弹出窗口的 cookie 的过期时间。我的目标是让 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>  

4

1 回答 1

2

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

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

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

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

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

于 2016-09-20T21:13:04.043 回答