1

加载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>
4

2 回答 2

1

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

<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/

于 2013-08-16T03:10:37.237 回答
1

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

<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>
于 2014-01-03T10:31:17.930 回答