0

I'm struggling to understand (and set) the expiration for this cookie I'm using on a site to fire a facnybox popup. My goal is to have the cookie set for one minute.

Cheers, and thanks in advance for any clarification you could provide.

<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>  

1 Answers1

2

Here's how you can do; first you have to set your cookie:

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

To set the expiration date, the docs says:

Create a cookie that expires 7 days from now, valid across the entire site: Cookies.set('name', 'value', { expires: 7 });

To get your cookie's value just use the get method provided by js-cookie: Cookies.get('name'); results itsValue

t3__rry
  • 2,817
  • 2
  • 23
  • 38