Search code examples
jquerycookieszurb-foundationjquery-cookiezurb-reveal

Store reveal modal cookie in user browser


I am currently using the Zurb foundation framework, I would like to create modal which will appear on page load. I would like this modal to store a cookie in the user browser so that if they have visit the site before they will not be shown the same modal again.

Here is how I attempted to implement this using jQuery which is used initiate foundation. Note I am using the jQuery no conflict wrapper because I am implementing this with word press.

jQuery(document).ready(function($){


$('#myModal2').foundation('reveal', 'open');

 var shown = $.cookie('dialogShown');
      if (!shown) {
            setTimeout(function() {
                  $('#myModal2').foundation({modal: true});
                  $.cookie('dialogShown', 'true');
            }, 2000);





      }});

This code is not giving me the desired output, the modal opens on page load over and over again, without storing the cookie, I would really appreciate if anyone could help me out with this. Thanks


Solution

  • In case anyone else is wondering I have posted a solution using the jQuery cookies plugin.

    jQuery(document).ready(function($) {
     if ($.cookie('modal_shown') == null) {
            $.cookie('modal_shown', 'yes', { expires: 7, path: '/' });
            $("#myModal2").foundation('reveal', 'open');
        }
    });