[thelist] JS cookie question (ignore previous)
Tom Dell'Aringa
pixelmech at yahoo.com
Fri Jan 10 13:24:01 CST 2003
--- Hans-Frédéric Fraser <hfraser at videotron.ca> wrote:
> > Might it have something to do with the cookie length? Its odd to
> get
> > results with the = sign in it...
>
> it is exactly that you did not take the = sign into account!
> here is a basic function i made to get simple cookie information!
>
>
> function getCookieData(whatCookie){
> var myCookie = new String(document.cookie);
> var myCookieHeader = whatCookie+"=";
> var myCookieStart = myCookie.indexOf(myCookieHeader);
> var myCookieEnd = myCookie.indexOf(';',myCookieStart);
>
> // if there is only one cokie you do not have the semicolon at
> the end
> if (myCookieEnd == -1){
> myCookieEnd = myCookie.length;
> }
> // extract data and check if the cookie exist
> if( myCookie.indexOf(myCookieHeader) != -1){
> myCookieStart = myCookieHeader.length;
> return myCookie.substring(myCookieStart, myCookieEnd);
> }
> else{
> // if the cookie does not exist well ... do what ever you
> want
> return 'noCookie';
> }
> }
>
> have fun!
This function seems to give me the WHOLE cookie (or at least, the
cookie up to the value of the supplied parameter). What I need is
only the cookie value of the label I specify, If I specify pid114 for
the cookie pid114=3, then I want ONLY that returned, not the whole
string.
Can I fix my original function to do that? (You said I have a problem
with the =)
Tom
=====
var me = tom.pixelmech.webDeveloper();
http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
More information about the thelist
mailing list