Rus
Eng
Автономный javascript скрипт для предупреждения об использовании cookies
Order site
By contacting me you will receive a reliable and knowledgeable contractor who will quickly and efficiently implement any task for you and your business.

All English-language materials have been translated fully automatically using the Google service

It is enough to put this code in your javascript file and the message will be shown to the user automatically

(function (window, undefined){
    "use strict";
    var document = window.document;
    function log() {
        if (window.console && window.console.log) {
            for (var x in arguments) {
                if (arguments.hasOwnProperty(x)) {
                    window.console.log(arguments[x]);
                }
            }
        }
    }
    function AcceptCookie() {
        if (!(this instanceof AcceptCookie)) {
            return new AcceptCookie();
        }
        this.init.call(this);
        return this;
    }
    AcceptCookie.prototype = {
        init: function () {
            var self = this;
            if(self.readCookie('COOKIE_ASSEPT') == null)
            {
                self.appendCss();
                self.addCookieBar();
            }
            var clear_cookie_arr = self.getElementsByClass("pjClearCookie", null, "a");
            if(clear_cookie_arr.length > 0)
            {
                self.addEvent(clear_cookie_arr[0], "click", function (e) {
                    if (e.preventDefault) {
                        e.preventDefault();
                    }
                    self.eraseCookie('COOKIE_ASSEPT');
                    document.location.reload();
                    return false;
                });
            }
        },
        getElementsByClass: function (searchClass, node, tag) {
            var classElements = new Array();
            if (node == null) {
                node = document;
            }
            if (tag == null) {
                tag = '*';
            }
            var els = node.getElementsByTagName(tag);
            var elsLen = els.length;
            var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
            for (var i = 0, j = 0; i < elsLen; i++) {
                if (pattern.test(els[i].className)) {
                    classElements[j] = els[i];
                    j++;
                }
            }
            return classElements;
        },
        addEvent: function (obj, type, fn) {
            if (obj.addEventListener) {
                obj.addEventListener(type, fn, false);
            } else if (obj.attachEvent) {
                obj["e" + type + fn] = fn;
                obj[type + fn] = function() { obj["e" + type + fn](window.event); };
                obj.attachEvent("on" + type, obj[type + fn]);
            } else {
                obj["on" + type] = obj["e" + type + fn];
            }
        },
        createCookie: function (name, value, days){
            var expires;
            if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                expires = "; expires="+date.toGMTString();
            } else {
                expires = "";
            }
            document.cookie = name+"="+value+expires+"; path=/";
        },
        readCookie: function (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;
        },
        eraseCookie: function (name) {
            var self = this;
            self.createCookie(name,"",-1);
        },
        appendCss: function()
        {
            var self = this;

            var cssCode = "";
            cssCode += "#a--bar { position: fixed; bottom: 0; left: 0; z-index: 9999; overflow-x: hidden; overflow-y: auto; width: 100%; max-height: 100%; padding: 20px 0; background: #000; border-top:1px solid #fff; opacity: 1; font-family: inherit; text-align: center;}";
            cssCode += "#a--bar * { padding: 0; margin: 0; outline: 0; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }";
            cssCode += "#a--bar .a--shell { width: 90%; margin: 0 auto; }";
            cssCode += "#a--bar a[href^=tel] { color: inherit; }";
            cssCode += "#a--bar a:focus,";
            cssCode += "#a--bar button:focus { outline: unset; outline: none; }";
            cssCode += "#a--bar p { font-size: 14px; line-height: 1.4; color: #fff; font-weight: 400; }";
            cssCode += "#a--bar .a--actions { padding-top: 10px; }";
            cssCode += "#a--bar .a--but { position: relative; display: inline-block; height: 40px; padding: 10px 30px; border: 0; background: #fff; opacity: 0.9; font-size: 14px; line-height: 14px; color: #000; text-decoration: none; vertical-align: middle; cursor: pointer; border-radius: 0; -webkit-appearance: none; -webkit-border-radius: 0; -webkit-transform: translateZ(0); transform: translateZ(0); -webkit-backface-visibility: hidden; backface-visibility: hidden; -moz-osx-font-smoothing: grayscale;-moz-transition: all 0.5s;-webkit-transition: all 0.5s;-o-transition: all 0.5s;-ms-transition: all 0.5s}";
            cssCode += "#a--bar .a--but:hover {background-color:#ccc}";
            cssCode += "@media only screen and (max-width: 767px) {";
            cssCode += "#a--bar { padding: 15px 0; }";
            cssCode += "#a--bar .a--shell { width: 96%; }";
            cssCode += "#a--bar p { font-size: 14px; }";
            cssCode += "}";
            var styleElement = document.createElement("style");
            styleElement.type = "text/css";
            if (styleElement.styleSheet) {
                styleElement.styleSheet.cssText = cssCode;
            } else {
                styleElement.appendChild(document.createTextNode(cssCode));
            }
            document.getElementsByTagName("head")[0].appendChild(styleElement);
        },
        addCookieBar: function(){
            var self = this;
            var htmlBar = '';
            htmlBar += '<div class="a--shell"><form action="#" method="post">';
            htmlBar += '<p>Для улучшения работы сайта и его взаимодействия с пользователями мы используем файлы cookie. Продолжая работу с сайтом, Вы разрешаете использование cookie-файлов. Вы всегда можете отключить файлы cookie в настройках Вашего браузера.</p>';
            htmlBar += '<div class="a--actions"><button type="button" class="a--but">Понимаю и соглашаюсь</button></div></form></div>';
            var barDiv = document.createElement('div');
            barDiv.id = "a--bar";
            document.body.appendChild(barDiv);
            barDiv.innerHTML = htmlBar;
            self.bindCookieBar();
        },
        bindCookieBar: function(){
            var self = this;
            var btn_arr = self.getElementsByClass("a--but", null, "button");
            if(btn_arr.length > 0)
            {
                self.addEvent(btn_arr[0], "click", function (e) {
                    if (e.preventDefault) {
                        e.preventDefault();
                    }
                    self.createCookie('COOKIE_ASSEPT', 'YES', 365);
                    document.getElementById("a--bar").remove();
                    return false;
                });
            }
        }
    };
    window.AcceptCookie = AcceptCookie;
})(window);

window.onload = function() {AcceptCookie = AcceptCookie();}

It looks like this:

Confirmation of the use of cookies

Original found here

Comments

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Please message me to discuss the task. I work remotely and officially (as a self-employed professional); my hourly rate is 1,800 RUB, and I can dedicate 3–4 hours a day to the project. I respond quickly, and the consultation is free.

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site