I'm trying to write some jQuery that, when the page loads, checks to see if a cookie has been set. If it hasn't been set, a modal opens, and a cookie is set for 6 hours.
It seems as though my cookie is not getting set, and I don't get either of the console.log statements in my if/else statements, whether the cookie is set or not. In the console, when I type $.cookie('email-signup')
, I get the error message "Cannot read property 'cookie' of undefined.
I've never really done this before, so any help or advice would be really appreciated!!!
My jQuery is:
jQuery(document).ready(function($) {
if (!!$.cookie('email-signup')) {
SetNewsletterCookie(email);
console.log('loaded');
}
function SetNewsletterCookie(email) {
$('#modalnewslettercontent').html('<iframe frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="100%" height="400" src="'+themePath+'views/newsletter-signup.html"></iframe>');
var date = new Date();
var minutes = 180;
date.setTime(date.getTime() + (minutes * 60 * 1000));
$.cookie('email-signup', 1, {expires: date, path: '/'});
console.log('cookie set');
}
});
According To Jquery-Cookie's docs, you'r
var
statement creats a variable and not a cookie. try again with their examples: