I've read multiple threads about this but none of them pertain to my code that I found and am using. My code from my js file is below, I would like the cookies to expire in 24 hours and I would think the code below would do that, but it doesn't. I just waited 24 hours after closing the browser window to see if the pop up occurred and it did not. Any help would be very helpful.
Code:
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// NOTE Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
So no cookies are set according to that right? But that doesn't make sense because if you go to the site the pop up occurs, then if you navigate back to the homepage(the only page that the pop up happens on) the pop up doesn't occur - thus letting me know the cookies are actually working.
Here's another js file that is associated with this page
Code:
//Launch lightbox upon load of document
$(document).ready(function() {
$('#sliderBox').stop().slideTo({
transition:1000,
left:'center',
inside:window
});
//Remember if user was shown lightbox
var cookieName = 'fam-offer';
if($.cookie(cookieName)!=cookieName){
$.cookie(cookieName, cookieName,{ path: '/' });
$('#sliderBox').slideTo({
transition:1000,
top:'center',
left:'center',
inside:window
});
}
jQuery(window).resize(function() {
$('#sliderBox').stop().slideTo({
transition:300,
top:'center',
left:'center',
inside:window
});
});
var closeWelcomeBox;
$("#closebtn").click(function(){
$('#sliderBox').stop().slideTo({
transition:1000,
top:-2000
});
$('#background').fadeOut(500);
closeWelcomeBox = true;
});
});
//Hide the window
function hideWindow(id){
$('#modal-mask').fadeOut(500);
$('.modal-window').hide();
}
//Launch (animate) the window
function launchWindow(id){
//Remember if user was shown lightbox
var cookieName = 'swag-email';
if($.cookie(cookieName)!=cookieName){
$.cookie(cookieName, cookieName,{ path: '/' });
}
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set height and width to mask to fill up the whole screen
$('#modal-mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#modal-mask').fadeIn(500);
$('#modal-mask').fadeTo("slow",0.85);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Dialog Dimensions
var dialogH = $(id).height();
var dialogW = $(id).width();
//Set the popup window to center
$(id).css('top', winH/2-dialogH/2);
$(id).css('left', winW/2-dialogW/2);
//transition effect
$(id).fadeIn(1000);
}
Maybe that would help anyone out with helping me : )