I have got two pages. example.com/php.com and example.com.
I use this function to set a page:
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value +" path=/";
}
However, what I am trying to do , is to delete all the cookies before setting it…so I use this:…
function deleteAllCookies() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
}
Then whenever I am on a certain page… I execute both of those functions , one after the other.
eraseCookie('user_details');
setCookie('user_details',document.referrer,365);
The problem is htat the cookie is never set..and I wonder why..
Try using this: https://github.com/carhartl/jquery-cookie
Simple and elegant, always gets the job done.