how to put cookie expires?

i want to insert expires time when i put cookie..
how can i do? T.T

Comments

  • Hello,

    you can set expires as the 4th parameter of put method (the 3rd parameter is domain):

    var date = new Date(...);
    webix.storage.cookie.put('mydata', {...}, null, date.toUTCString()); 
    
  • edited March 28

    How can I check the cookie still alive ?

    credentials = {
                                "access_token": mytoken,
                                "expires_in": 3600,
                                "uname": data.username
                            };
                            var now = new Date();
                            console.log(now.toUTCString());
                            var time = now.getTime();
                            time += credentials.expires_in * 1000;
                            now.setTime(time);
                            console.log(now);
                            webix.storage.cookie.put('cred', credentials,null, now.toUTCString());
    
    if(cookieAvailable){
    //clear
    webix.storage.cookie.remove('cred');
    }
    
  • webix API wrapper doesn't provide a helper to get the expiration date of cookie. When cookie expires, cookie.get API returns null

  • What about to set cookie path.
    Webix cookie storage put method doesn't provide a way to set it.
    Does someone know how to set the cookie path?

  • edited March 13

    Read the comments below docs:
    https://docs.webix.com/api__storage.cookie_put.html

    and source code of webix:

    webix.storage.cookie = {
        put:function(name, data, domain, expires ){
            if(name && window.JSON){
                document.cookie = name + "=" + escape(webix.stringify(data)) +
                (( expires && (expires instanceof Date)) ? ";expires=" + expires.toUTCString() : "" ) +
                (( domain ) ? ";domain=" + domain : "" ) + 
                (( webix.env.https ) ? ";secure" : "");
            }
        },
    
Sign In or Register to comment.