繁体   English   中英

jQuery Cookie.js保存Cokkie

[英]JQuery Cookie.js Save cokkie

嗨,我正在使用jquery cookie.js存储cookie。

我已经搜索了代码,并且使用cookie.js插件可以正常工作,但是我遇到了一个问题,当我刷新页面时,cookie会自动保存并且不会显示弹出窗口。 当任何用户在网站上输入时,会弹出一个窗口,并且用户必须单击继续按钮才能在网站上输入,

我基本上不允许用户在单击继续按钮之前进入站点。

这是我的HTML代码

<div id="popup-container">
<div class="wrapper">
<div id="popup-window">
  <div class="splash-bg">
    <h1>Are You Over 18? Click Continue if you are or return to previous 
      page</h1>
  <a type="button" class="close">Continue</a>
</div>
</div>

这是我正在使用的js代码

<script type="text/javascript">
     jQuery(document).ready(function(){  
      jQuery('#popup-container a.close').click(function(){
          jQuery('#popup-container').fadeOut();
          jQuery('#active-popup').fadeOut();
      });

      var visits = jQuery.cookie('visits') || 0;
      visits++;

      jQuery.cookie('visits', visits, { expires: 1, path: '/' });

      console.debug(jQuery.cookie('visits'));

      if ( jQuery.cookie('visits') > 1 ) {
        jQuery('#active-popup').hide();
        jQuery('#popup-container').hide();
      } else {
          var pageHeight = jQuery(document).height();
          jQuery('<div id="active-popup"></div>').insertBefore('body');
          jQuery('#active-popup').css("height", pageHeight);
          jQuery('#popup-container').show();
      }

      if (jQuery.cookie('noShowWelcome')) { jQuery('#popup-
      container').hide(); jQuery('#active-popup').hide(); }
    }); 

    jQuery(document).mouseup(function(e){
      var container = jQuery('#popup-container');

      if( !container.is(e.target)&& container.has(e.target).length === 0)
      {
        container.fadeOut();
        jQuery('#active-popup').fadeOut();
      }

    });
 </script>

当您访问的cookie数量很多时,cookie可能不是cookie数组中的第一个cookie,因此您必须尝试使用​​以下两种方法来获取该cookie

jQuery.cookie('visits')

jQuery.cookie(' visits')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM