简体   繁体   English

使用jQuery Cookie显示隐藏的内容

[英]Show Hidden Content with jQuery Cookie

I'm trying to get a div to display after x time for new visitors, and display immediately for returning visitors. 我试图在x时间之后为新访问者显示一个div,并立即显示给回​​访者。 I can't figure out why this won't work and hoping someone can point out the error. 我无法弄清楚为什么这不起作用,希望有人可以指出错误。

Using jQuery Cookie Plugin: https://github.com/carhartl/jquery-cookie 使用jQuery Cookie插件: https//github.com/carhartl/jquery-cookie

//Make Hidden Content Visible       
        jQuery(document).ready(function($) {

            // set the delay with the following vars
            var hour = 0;
            var minutes = 0;
            var secs = 7;
            var thisdelay = (hour*60*60*1000) + (minutes * 60 * 1000) + (secs * 1000);

            //checks a cookie value
            //If no cookie found, add a cookie for the next visit
            if($.cookie('returningvisitor') === null) {
                var duration = 1; // days until cookie expires
                $.cookie('returningvisitor', 'true', { expires: duration});

                //then wait until delay to display 
                $(".hideshow").delay(thisdelay).fadeIn("fast");
            }
            else {
                //immediately display the content
                $(".hideshow").css("display", "block");

            }
        });

and... 和...

<div class="hideshow" style="display:none;"><p>Hello World</p></div>

And the JS Fiddle... http://jsfiddle.net/mp2E8/1/ 和JS小提琴... http://jsfiddle.net/mp2E8/1/

Thanks! 谢谢!

According the documentation: 根据文件:

$.cookie('not_existing'); // => undefined

so in your: 所以在你的:

$.cookie('returningvisitor') === null

should be: 应该:

$.cookie('returningvisitor') === undefined

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

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