I want to save cookie one and I want to keep updating it on a site basis, not page wise.
Currently I have 5 headers in my navigation box which is static to all pages and on click of header; I am saving header text to the cookie and on every page selected header retrieving. But the problem is that the cookie is saving page wise not site wise. Each page is creating a new cookie.
Code below,
function setCookie(c_name,value,expdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + expdays);
var c_value=escape(value) + ((expdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
function getCookie(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
}
$(function($) {
var menuClickedOld1 = getCookie("SPLeftNavigation");
if(menuClickedOld1!=null && menuClickedOld1!=""){
$('li:contains('+menuClickedOld1+') ul').show();
alert("from cookie "+menuClickedOld1);
}
else{
alert('No values');
}
$('.arrw').click(function() {
var lname=$(this).parent().text();// selected header name;
setCookie("SPLeftNavigation",lnName,1);
});
});
How can I resolve this problem I already spent a day on it... as it's for production.
Thanks!!