Jquery Click Popup and cookies (Show popup once)

前端 未结 2 2032
执念已碎
执念已碎 2021-01-23 22:07

Load Jquery

    
    

        
相关标签:
2条回答
  • 2021-01-23 22:34

    Are you including the jQuery cookie plugin, https://github.com/carhartl/jquery-cookie. You can find on CDNJS at 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>
    

    Works for this fiddle http://jsfiddle.net/WyYZ8/

    0 讨论(0)
  • 2021-01-23 22:39

    I had the same problem and I found this solution:

    <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>
    
    0 讨论(0)
提交回复
热议问题