JavaScript cookie client
before, I have been using JAVA or PHP as my cookie but that was a bad cookie ever, as I new to programming I use this, after that I find out that if user click on back button of the browser then it will do nothing related to the server side, so I decide to search for client side cookie, and that is javascriipt
// and here is the way you create function for call to make the cookie.
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
// and here is the way you read it back
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
// you can clear it by this function. actaully you can make another function to overwrite the cookie name
function eraseCookie(name) {
createCookie(name,"",-1);
}
