Skip to content

Instantly share code, notes, and snippets.

@erikpantzar
Last active November 28, 2019 15:40
Show Gist options
  • Save erikpantzar/f182e610aaab1109e2cd0a257af536c4 to your computer and use it in GitHub Desktop.
Save erikpantzar/f182e610aaab1109e2cd0a257af536c4 to your computer and use it in GitHub Desktop.
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.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 ""; // HAS NO COOKIE
}
const THE_COOKIE_NAME = 'hasSeenBlackFriday2019'
if (getCookie(THE_COOKIE_NAME) === 'seen') {
if (getCookie(THE_COOKIE_NAME) !== "") {
// DO NOT SHOW POPUP!!!
} else {
// SHOW POPUP!!
// THEN SET COOKIE
setCookie(THE_COOKIE_NAME, 'seen', 30)
}
@erikpantzar
Copy link
Author

Hihihih

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment