|
-
Nov 18th, 2010, 07:47 PM
#1
Thread Starter
Hyperactive Member
[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.
-
Nov 19th, 2010, 06:15 AM
#2
Thread Starter
Hyperactive Member
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"],
Last edited by seanwpb; Nov 19th, 2010 at 06:16 AM.
Reason: typo
-
Nov 25th, 2010, 08:18 AM
#3
Frenzied Member
Re: [RESOLVED] Javascript read cookie
This is the Java forum not the JavaScript forum, they are two completely different languages - a common mistake.
-
Nov 27th, 2010, 04:09 AM
#4
Re: [RESOLVED] Javascript read cookie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|