Help With Cookie Expiry

Discussion in 'Javascript' started by Hardeep Rakhra, Jan 15, 2004.

  1. 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,Path,Domain,Secure){
    if (Expiry != null) {
    var datenow = new Date();
    datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry));
    Expiry = datenow.toGMTString();
    }

    Expiry = (Expiry != null) ? '; expires='+Expiry : '';
    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.indexOf(Name + '=') == -1) return null;
    var start = cookies.indexOf(Name + '=') + (Name.length + 1);
    var finish = cookies.substring(start,cookies.length);
    finish = (finish.indexOf(';') == -1) ? cookies.length : start +
    finish.indexOf(';');
    return unescape(cookies.substring(start,finish));
    }

    function setActiveStyleSheet(pTitle) {
    var vLoop, vLink;
    for(vLoop=0; (vLink = document.getElementsByTagName("link")[vLoop]);
    vLoop++) {
    if(vLink.getAttribute("rel").indexOf("style") != -1 &&
    vLink.getAttribute("title")) {
    vLink.disabled = true;
    if(vLink.getAttribute("title") == pTitle) vLink.disabled = false;
    }
    }
    }

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

    if (document.cookie.indexOf('style')!=-1) {
    css = readCookie('style');
    //ACTIVATE SELECTED STYLE SHEET
    setActiveStyleSheet(css)
    }
    Hardeep Rakhra, Jan 15, 2004
    #1
    1. Advertising

  2. Hardeep Rakhra wrote:
    > 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)
    >


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

    It's from;

    http://www.notestips.com/80256B3A007F2692/1/NAMO5GK2NM
    Hardeep Rakhra, Jan 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    715
  2. Milsnips
    Replies:
    1
    Views:
    414
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 15, 2007
  3. sheraz_aries

    cookie expiry - classic asp

    sheraz_aries, Mar 20, 2009, in forum: .NET
    Replies:
    0
    Views:
    807
    sheraz_aries
    Mar 20, 2009
  4. Ray

    cookie expiry date problem

    Ray, Apr 21, 2004, in forum: ASP .Net Security
    Replies:
    0
    Views:
    148
  5. Vince C.
    Replies:
    1
    Views:
    196
Loading...

Share This Page