[RESOLVED] Javascript read cookie
i have this js file that i use as part of a drop down menu.
Code:
var anylinkmenu1={divclass:'anylinkmenu', inlinestyle:'', linktarget:''}
anylinkmenu1.items=[
["Home", "../index.php"],
["Logout", "../process.php"]//no comma following last entry!
]
]
what i want to do is read a cookie that already exist called siteid then append the menu caption "Home" with the value in the cookie. i have tried starting the file with this
var siteid = get_cookie ( "siteid" );
then placing the siteid variable in the ["Home", "../index.php"],
but with no luck.
Re: Javascript read cookie
I got it to work. what i did was to add this at the start of the file to read the cookie and remove any + signs
Code:
function cookie_read(c_name)
{
var comp = c_name + "=";
var cooks = document.cookie.split(';');
for(var i=0;i < cooks.length;i++)
{
var check = cooks[i];
while (check.charAt(0) == " ")
check = check.substring(1,check.length);
if (check.indexOf(comp) == 0)
return check.substring(comp.length,check.length);
}
return null;
}
UnitChangedTo = cookie_read('UnitChangedTo')
UnitChangedTo = UnitChangedTo.replace("+"," ");
then in the menu code
Code:
[UnitChangedTo, "../GetUnitNumber.php"],
Re: [RESOLVED] Javascript read cookie
This is the Java forum not the JavaScript forum, they are two completely different languages - a common mistake.
Re: [RESOLVED] Javascript read cookie