Reputation: 499
I'm trying to get a div to display after x time for new visitors, and display immediately for returning visitors. 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
//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/
Thanks!
Upvotes: 1
Views: 256
Reputation: 2536
According the documentation:
$.cookie('not_existing'); // => undefined
so in your:
$.cookie('returningvisitor') === null
should be:
$.cookie('returningvisitor') === undefined
Upvotes: 3