Reputation: 971
I've been out of web development for a while now so very rusty. I need to make a cookie
im struggling and would really appreciate some guidance.
thanks so much
Upvotes: 2
Views: 1333
Reputation: 971
Heres the messy solution i cam up with in case anyone wanted to know:
function nameDefined(ckie,nme)
{ var splitValues var i for (i=0;i tvalue=getCookieValue(nvpair,cname) //Gets the value of the cookie if (tvalue == cvalue) return true else return false } else return false } function redirectLink() { if (testCookie("here10", "yes")) { //window.location="here.html" //Go to the location indicating the user has been here //alert("there"); window.document.getElementById("indicator").style.display = "none"; } else{ //alert(" not there"); var futdate = new Date() //Get the current time and date var expdate = futdate.getTime() //Get the milliseconds since Jan 1, 1970 expdate += 10000 //expires in 1 hour(milliseconds) futdate.setTime(expdate) var newCookie="here10=yes; path=/;" //Set the new cookie values up newCookie += " expires=" + futdate.toGMTString() window.document.cookie=newCookie //Write the cookie // window.location="not.html" //Go to the location indicating the user has not been here
window.document.getElementById("indicator").style.display = "block";
} }
Upvotes: 0
Reputation: 3542
With JavaScript you can
- read cookie:
var coo = [],
a;
if(document.cookie != ''){
$.each(document.cookie.split('; '), function(i, val){
a = val.split('=');
coo[a[0]] = a[1];
});
}
here we have a coo
with all cookies (coo['Cookie1'] == 'value'
).
- set cookie:
document.cookie = 'Cookie_1='+'value for this cookie';
BTW code is using jQuery for $.each.
Upvotes: 1