【问题标题】:Jquery Click Popup and cookies (Show popup once)Jquery Click Popup and cookies (Show popup once)
【发布时间】:2014-01-03 18:31:17
【问题描述】:

加载 Jquery

    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

我正在尝试让弹出窗口仅加载一次,然后再过 31 天不再显示。

    <script type="text/javascript"><!--
    jQuery(document).ready(function()
    {
if (jQuery.cookie('test_status') != '1')
{
    setTimeout(function()
    {
        jQuery('.lightbox-handle').reveal()
        jQuery('.lightbox-handle').click();
        jQuery.cookie('test_status', '1', { expires: 31}); 
    }, 1000);
}
    });
    //--></script>

【问题讨论】:

    标签: jquery cookies popup click


    【解决方案1】:

    您是否包含 jQuery cookie 插件 https://github.com/carhartl/jquery-cookie。您可以在 CDNJS 上找到 http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.3.1/jquery.cookie.min.js

    <script type="text/javascript"
            src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript"
            src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.3.1/jquery.cookie.min.js"></script>
    <script type="text/javascript">
        $(function() {
            if ($.cookie('test_status') != '1')
            {
                setTimeout(function()
                {
                    alert('foo');
                    jQuery.cookie('test_status', '1', { expires: 31}); 
                }, 1000);
            }
        }
    </script>
    

    适用于这个小提琴http://jsfiddle.net/WyYZ8/

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,我找到了这个解决方案:

      <script type="text/javascript">
      var x = document.cookie;
          if (x =="")
            {
                      var url = window.location;
                  if (url!="http://localhost/test/jquery-popup.html")
                      {
                      $(document).ready(function(){
                          setTimeout(function() {
                              alert( "the current url is "+url+ "");
                              //$.fn.colorbox({html:'<div style="width:301px;height:194px;"><a href="http://livebook.in/"><img src="res/homer.jpg" style="width:301px;height:194px;" alt="The linked image" /></a></div>', open:true});
                          }, 500);
                      });
                      } 
                  else 
                      {
                      $(document).ready(function(){
                      setTimeout(function() {
                          //alert( "else");
                          $.fn.colorbox({html:'<div style="width:301px;height:194px;"><a href="http://livebook.in/"><img src="res/homer.jpg" style="width:301px;height:194px;" alt="The linked image" /></a></div>', open:true});
                      }, 500);
                      setTimeout(function(){$.fn.colorbox.close()},3000);
                      //document.cookie="apparsoSI";
                          var d = new Date();
                          d.setTime(d.getTime()+(30*24*60*60*1000)); //expire in 30 days
                          var expires = "expires="+d.toGMTString();
                          document.cookie = "apparsoYES" + "=" + "YES" + "; " + expires;
                          });
                      }
           }
      
          else
              {
              alert( "cookie ok");
      
              }
      
      </script>
      

      【讨论】:

        猜你喜欢
        • 2020-01-03
        • 1970-01-01
        • 1970-01-01
        • 2022-12-02
        • 1970-01-01
        • 1970-01-01
        • 2023-03-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多