Re: JavaScript to display all cookies

by "Ken" <webmaster(at)fcs.net>

 Date:  Thu, 24 Aug 2000 13:29:54 -0700
 To:  "hwg languages" <hwg-languages(at)hwg.org>
 References: 
  todo: View Thread, Original
Excellent! It works perfectly.
Thank you _very_ much for the insights and suggestions.

_Ken Creason
webmaster(at)fcs.net


----- Original Message ----- 
From: "Cyanide _7" <leo7278(at)hotmail.com>
To: <webmaster(at)fcs.net>
Sent: Thursday, August 24, 2000 12:44 PM
Subject: Re: JavaScript to display all cookies


> try the replace method of the String object, and you should be able to do 
> this from the start, rather than once on each name or value. a lot of your 
> variables are *disposable* as i like to call them. used once, then not 
> again, so i like to reuse variables on account that they can be any data 
> type at any time. just a few other readability notes, in many C based 
> languages, "i" is the standard looping counter, and you run through an array 
> by its length, not until its undefined.
> 
> function getAllCookies() {
>   var cookies  = document.cookie.replace(/ /g,"").split(";");
>   for (var i = 0; i < cookies.length; i++){
>     cookiePair = cookies[i].split("=");
>     document.write("["+cookiePair[0]+"] = ["+
>                    cookiePair[1]+"]<br><br>");
>   }
> }
> 
> does this suit your needs? - Cyanide_7
> 
> >I reworked it a little to take advantage
> >of your suggestion and have this:
> >
> >function getAllCookies() {
> >     var everycookievalue  = document.cookie;
> >     var pairsSplit = everycookievalue.split(";");
> >     var patternNospace = /[^\s]+/;
> >     var finalName;
> >     var finalValue;
> >     for ( count=0 ; ( pairsSplit[count] != undefined ) ; count++ ) {
> >         elementsSplit = pairsSplit[count].split("=");
> >         finalName = elementsSplit[0].match(patternNospace);
> >         document.writeln("[" + finalName + "] = ");
> >         finalValue = elementsSplit[1].match(patternNospace);
> >         document.writeln("[" + finalValue + "]<BR><BR>");
> >     }
> >}
> >
> >Please let me know if you know of a better way to
> >remove spaces from the elements (I'm not too sure
> >about the regex pattern).
> >Thanks,
> >_Ken
> >
> >
> >
> >
> >----- Original Message -----
> >From: "Cyanide _7" <leo7278(at)hotmail.com>
> >To: <webmaster(at)fcs.net>
> >Cc: <hwg-languages(at)hwg.org>
> >Sent: Wednesday, August 23, 2000 11:54 PM
> >Subject: Re: JavaScript to display all cookies
> >
> >
> > > not sure what you want, but document.cookie will return the string of 
> >all
> > > valid cookies for a given page. if you want to match a pattern in that
> > > string, i see why not. if you want to go further and seperate the 
> >cookies,
> > > they are semicolon delimited, and you can split the string with that 
> >char to
> > > get an array, each containing a cookie. split each cookie further with 
> >the
> > > equal sign, and you can cookies divided into name and value. beyond 
> >that, im
> > > not sure what you want to do. - Cyanide_7
> > >
> > > >Anybody have a good JavaScript function that
> > > >returns or displays all cookies valid for a page?
> > > >I've got plenty of scripts for finding a cookie
> > > >with a particular name, but none that show all.
> > > >I'm working on one that uses text.match() with
> > > >regex but I'd rather not spend the time
> > > >to reinventthewheel.
> > > >
> > > >Thanks,
> > > >_Ken Creason
> > > >webmaster(at)fcs.net
> >
> 
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
> 
> 

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA