I have three sites with url as -
www.xyz.com
account.xyz.com
admin.xyz.com
I want that all three share the same cookie. If I open any of the above URL then my modal pop-up should be visible and cookie should be stored, but if I try to open other link then the pop-up should not be visible as cookie is set.
I have developed the logic and works perfectly in localhost with different ports, but for live site it doesn't. It only works for one site! Can some one help me with the solution for this.
Thanks in advance!
Code -
$(window).load(function() {
$('#slideinModal').modal('show');
var popVisible = true;
if (popVisible === true) {
$('body').css({
'overflow': 'inherit',
'padding': '0'
});
// Set Cookie
function setCookie(cname, cvalue, exdays) {
var now = new Date();
var time = now.getTime();
time += 24 * 3600 * 1000;
now.setTime(time);
document.cookie = 'username=' + cname + '; expires=' + now.toUTCString() + '; path=/';
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
// Check Cookie
function checkCookie() {
var user = getCookie("username");
if (user != "") {
dynamiClass();
//alert("Welcome again " + user);
} else {
user = popVisible;
if (user != "" && user != null) {
setCookie("username", user, 30);
}
}
}
checkCookie();
popVisible = false;
}
});
// Toggle Logic
$('body').click(function (evt) {
if ($(evt.target).closest('.modal-backdrop').length) {
dynamiClass();
}
});
// Close Modal on Overlay
$('.toggle-offer-modal').on('click', function (e) {
e.preventDefault();
dynamiClass();
});
$('.toggleSlide-button').click(function () {
dynamiClass();
});
function dynamiClass() {
var oh = 250; //$('#slideinModal .modal-content').outerHeight();
$('.toggle-offer-modal').parents('#slideinModal').toggleClass('toggleActive');
if ($('#slideinModal').hasClass('toggleActive')) {
$('.toggleSlide-button').addClass('open');
$('.toggle-offer-modal').parents('#slideinModal').css('bottom', -oh + 40);
$('body').addClass('slideInOn');
$('body').removeClass('modal-open');
$('body').attr('style', '');
}
else {
$('.toggleSlide-button').removeClass('open');
$('.toggle-offer-modal').parents('#slideinModal').css('bottom', 0);
$('body').removeClass('slideInOn');
$('body').css({ 'overflow': 'inherit', 'padding': '0' });
}
}