Re: JavaScript to display all cookies

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

 Date:  Thu, 24 Aug 2000 09:32:12 -0700
 To:  "hwg languages" <hwg-languages(at)hwg.org>
 Cc:  "Agent Starling" <agentstarling(at)geeksara.com>
 References:  hotmail
  todo: View Thread, Original
Sorry, I forgot to mention the parsing-out-the-values
part of what I wanted to do :)
I worked it out and ended up with this:

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!-- // BEGIN Hide

getAllCookies();

function getAllCookies() {
    var everycookievalue  = document.cookie; 
    var mySplit = everycookievalue.split(";");
    var patternName    = /^[^=]+/;
    var patternValue   = /[^=]+$/;
    var patternNospace = /[^\s]+/;
    var resultName;
    var resultValue;
    for ( count=0 ; ( mySplit[count] != undefined ) ; count++ ) {
        resultName = mySplit[count].match(patternName);
        resultName = resultName[0].match(patternNospace);
        document.writeln("[" + resultName + "] = ");
        resultValue = mySplit[count].match(patternValue);
        resultValue = resultValue[0].match(patternNospace);
        document.writeln("[" + resultValue + "]<BR><BR>");
    }
}

// END hide -->
</SCRIPT>

I'm sure it is not very bullet-proof (I'm no wizard at RegEx,
or JavaScript for that matter) but it seems to work alright 
for my purposes.
Any suggestions would be appreciated.

_Ken Creason
webmaster(at)fcs.net




----- 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