Reputation: 11
I'm a JS newbie (technically, I just sort of make things up as I go), so please have mercy and draw me pictures with crayons when you explain things.
We have three separate sites:
With all the GDPR fun, I've had a crash course in cookies. The script below is out on www.example.com/home and will set and read the cookie back and forth for all three sites listed above, but for web.example.com, it shows the cookie as set for ".example.com" but constantly re-displays the banner with each page load. And for the Acquia domains, it won't set or dismiss the cookie. I don't want to break whatever is working, but is there a way to both specify the domain as ".example.com" so that it works with the product site and also set/dismiss it when editing the site?
/* functions for getting and setting cookies */
function setCookie(c_name,value,exdays){
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value + ";domain=.example.com;path=/";
}
function getCookie(c_name){
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++){
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x===c_name){
return unescape(y);
}
}
}
jQuery(document).ready(function($){
function displayCookieAccept(){
var cookieAccepted = getCookie('cookie-accept');
if(cookieAccepted !== 't'){
var cookieBox = $('<div class="cookie-accept"></div>');
var cookieText = '<p>This site uses cookies. By continuing to browse this site you are agreeing to our use of cookies. <a href="#" id="accept-cookie">Continue</a> or <a href="/home/privacy-policy" id="privacy">Find out more</a>.</p>';
$(cookieBox).html(cookieText);
$('body').prepend(cookieBox);
$(cookieBox).slideDown('fast');
$('#accept-cookie').click(function(){
setCookie('cookie-accept', 't', 1825);
$(cookieBox).hide();
});
}
}
displayCookieAccept();
});
Upvotes: 1
Views: 68