Skip to content

Instantly share code, notes, and snippets.

@sukhikh18
Last active February 20, 2019 07:56
Show Gist options
  • Save sukhikh18/10ebecf314f0cfa98801bd9e668ce519 to your computer and use it in GitHub Desktop.
Save sukhikh18/10ebecf314f0cfa98801bd9e668ce519 to your computer and use it in GitHub Desktop.
Once do action via cookies
var cookieName = 'oncePopup';
// if cookie exists
if( 0 < getCookie(cookieName) ) return;
var date = new Date(new Date().getTime() + 1 * 60 * 60 * 1000); // 1 hour
document.cookie = cookieName + "=1; path=/; expires=" + date.toUTCString();
function getCookie(name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment