I am using jquery cookies plugin, in order to increment the value of the cookie each time a user comes to a page. I am doing this so I can display something on the first visit, then something different on the second visit and then nothing after that.
So i need to determine if its the user’s first visit, their second visit and all visits after.
var cookieTime = jQuery.cookie('shownDialog');
cookie_value = parseInt(cookieTime);
if (cookieTime != 'true') {
jQuery.cookie('shownDialog', '1', 'true', {expires: 7});
cookie_value ++;
}
else if (cookieTime == 'true' && cookie_value > 0){
cookie_value ++;
}
This code i’ve been using gets reset every time i refresh the page. Instead of holding the value inside the cookie. I am not sure the best way of retaining the value of the cookie and incrementing it each time as the page gets refreshed?
I don’t think
is the valid form. It’s supposed to be
Source: https://github.com/carhartl/jquery-cookie
If you want to check if the cookie is set, check if it’s null.