Beispiel Cookie

Beispiel Cookie

by mtenschert

HTML

Cookie

JavaScript

var already_ad_customer = "already_ad_customer";
    function setCookie(key, value) {
        var expires = new Date();
        expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
        document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
    }
    setCookie(already_ad_customer, 1);
    
    
    var cookie = "already_ad_customer";
    var getCookie = function(cname) {
        var name = cname + "=";
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.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 '';
    }
    var checkCookie = function() {
        cookie = getCookie(cookie);
    }
    checkCookie();