I've searched for the answer to this question and only found half solutions to my issue.
I'm trying to write a cookie based on an URL parameter, and then hide or show page content based on if that cookie is present.
I'm trying to use js-cookie.
If someone comes to the site with the parameter ?ent=a1 attached to their url, a cookie would be written called ent_afil with the value of one. If the ent_afil cookie is present a div with the ID default-content is hidden and a div with the ID a1 is shown. If the URL parameter isn't present, no cookie is written and the default-content div remains.
function SetCookie() {
var url = window.location.search;
if(url.indexOf('?ent=a1') !== -1)
Cookies.set('ent_afil', 'one', { expires: 5 });
}
if (Cookies.get("ent_afil") == 'one')
{
$("#default-content").hide();
$("#a1").show();
}
else {
$("#default-content").show();
$("#a1").hide();
}