Last active
February 20, 2019 07:56
-
-
Save sukhikh18/10ebecf314f0cfa98801bd9e668ce519 to your computer and use it in GitHub Desktop.
Once do action via cookies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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