Luke C
Luke C

Reputation: 192

Cookie expiration time

I am after some help with my javascript code. I am afraid I have no experience with JS, only html and css. I have a cookie policy notice on my website that I have installed from a friend. I am wondering if someone can tell me the expiration date I currently have in my code (as I have no clue).. Also if someone could recommend an expiration time for the EU Cookie Law policy if my code isn't appropriate already?

Code Below:

var euCookie = {
    g: function(){
        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("euCookieLaw") == 0) return c.substring("euCookieLaw".length,c.length);
        }

        return null;
    },
    s: function(value){
        var date = new Date();
        date.setTime(date.getTime()+315532800000);

        document.cookie = "euCookieLaw="+value+"; expires="+date.toGMTString()+"; path=/";
    }

Upvotes: 1

Views: 5002

Answers (1)

krisku
krisku

Reputation: 3993

Your example code sets the cookie to expire 315532800000 milliseconds from now, i.e. that resolves to 3652 days or just about 10 years into the future.

Upvotes: 3

Related Questions