Help With Cookie Expiry

H

Hardeep Rakhra

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)
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top