Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- $(document).ready(function(e) {
- const COOKIE_NAME = "cookie-consent";
- const cookiesWrap = "coock";
- const cookiesConsentBtn = "coock-btn";
- function setCookie(name, value, days) {
- var expires = "";
- if (days) {
- var date = new Date();
- date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
- expires = "; expires=" + date.toUTCString();
- }
- document.cookie = name + "=" + (value || "") + expires + "; path=/";
- }
- function getCookie(name) {
- var nameEQ = name + "=";
- 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, c.length);
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
- }
- return null;
- }
- function showPopup(popupSelector) {
- const popupElement = document.getElementById(popupSelector);
- popupElement.style.display = "flex";
- }
- function closePopup(popupSelector) {
- const popupElement = document.getElementById(popupSelector);
- popupElement.style.display = "none";
- }
- function attachConsentBtnListener(consentBtnSelector) {
- document.getElementById(consentBtnSelector).addEventListener("click", function(e) {
- setCookie(COOKIE_NAME, true, 10000);
- closePopup(cookiesWrap)
- });
- }
- if(!getCookie(COOKIE_NAME)) {
- attachConsentBtnListener(cookiesConsentBtn);
- showPopup(cookiesWrap);
- }
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment