Help With Cookie Expiry

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hardeep Rakhra

    Help With Cookie Expiry

    Hi i have a snippet of JS that i want to change so that the cookie it
    creates lasts only 48 hours. (or any other length of time i decide, but
    48hours seems right for now)

    Only thing i can't figure out how it specifies the expiry time.

    Thanks!

    Hardeep

    -----
    function makeCookie(Name ,Value,Expiry,P ath,Domain,Secu re){
    if (Expiry != null) {
    var datenow = new Date();
    datenow.setTime (datenow.getTim e() + Math.round(8640 0000*Expiry));
    Expiry = datenow.toGMTSt ring();
    }

    Expiry = (Expiry != null) ? '; expires='+Expir y : '';
    Path = (Path != null)?'; path='+Path:'';
    Domain = (Domain != null) ? '; domain='+Domain : '';
    Secure = (Secure != null) ? '; secure' : '';

    document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain
    + Secure;
    }

    function readCookie(Name ) {
    var cookies = document.cookie ;
    if (cookies.indexO f(Name + '=') == -1) return null;
    var start = cookies.indexOf (Name + '=') + (Name.length + 1);
    var finish = cookies.substri ng(start,cookie s.length);
    finish = (finish.indexOf (';') == -1) ? cookies.length : start +
    finish.indexOf( ';');
    return unescape(cookie s.substring(sta rt,finish));
    }

    function setActiveStyleS heet(pTitle) {
    var vLoop, vLink;
    for(vLoop=0; (vLink = document.getEle mentsByTagName( "link")[vLoop]);
    vLoop++) {
    if(vLink.getAtt ribute("rel").i ndexOf("style") != -1 &&
    vLink.getAttrib ute("title")) {
    vLink.disabled = true;
    if(vLink.getAtt ribute("title") == pTitle) vLink.disabled = false;
    }
    }
    }

    function selectStyle (vCookieName, vSelection) {
    //WRITE COOKIE
    makeCookie(vCoo kieName, vSelection, 90, '/');
    //ACTIVE SELECTED ALTERNAT STYLE SHEET
    setActiveStyleS heet(vSelection )
    }

    if (document.cooki e.indexOf('styl e')!=-1) {
    css = readCookie('sty le');
    //ACTIVATE SELECTED STYLE SHEET
    setActiveStyleS heet(css)
    }
  • Hardeep Rakhra

    #2
    Re: Help With Cookie Expiry

    Hardeep Rakhra wrote:[color=blue]
    > Hi i have a snippet of JS that i want to change so that the cookie it
    > creates lasts only 48 hours. (or any other length of time i decide, but
    > 48hours seems right for now)
    >[/color]

    One other thing, seem this won't work with Firebird 0.7

    It's from;



    Comment

    Working...