I've tried the various work arounds that have been mentioned in similar posts but I am still unable to make my modal window show only once per browsing session using the cookie. This is what my script looks like, if anyone can help me that would be perfect:

<script>  
$(document).ready(function() {
    if ($.cookie('modal_shown') == null) {
        $.cookie('modal_shown', 'yes', { expires: -1, path: '/' });
        setTimeout(function(){
          $("#modal").fadeIn(500);
        },7000);
    }
});
</script>
<script>
    $('#close').click(function() {
      $('#modal').hide();
    }
);
  </script>

And this is what my links look like:

<!--Modal-->
      <script type="text/javascript"  src="http://code.jquery.com/jquery-latest.min.js"></script>
      {{ "jquery-cookie.js" | asset_url | script_tag }}

没有正确的解决方案

其他提示

the expires option is not working. please try like this

$(document).ready(function () {
alert('I am ready');
if ($.cookie('modal_shown') == null) {
    $.cookie('modal_shown', 'yes');

    setTimeout(function(){
      $("#modal").fadeIn(500);
    },7000);
}
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top