W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2010

[whatwg] HTML Cookie API

From: Adam Barth <w3c@adambarth.com>
Date: Wed, 24 Feb 2010 13:07:02 -0800
Message-ID: <5c4444771002241307j1069338as27c50112fcf51a16@mail.gmail.com>
On Wed, Feb 24, 2010 at 11:11 AM, Nicholas Zakas <nzakas at yahoo-inc.com> wrote:
> I like the idea of creating an easier way to deal with cookies (which is why I wrote the YUI Cookie utility way back when). The thing that seems to be missing in your proposed API is what I consider to be the most common use case: retrieving the value of a single cookie. There's not many times when I need to get every single cookie that's available on the page, but there are plenty of times when I want to check the value of a single cookie. Using your API, getting the value of a single cookie with a known name becomes:
>
> ? ?document.getCookies(function(cookies) {
> ? ? ?for (var i=0; i < cookies.length; ++i){
> ? ? ? ? ?if(cookies[i].name == "my_cookie_name"){
> ? ? ? ? ? ? ?doSomething(cookies[i]);
> ? ? ? ? ?}
> ? ? ?}
> ? ?});
>
> That seems like a lot of work just to retrieve a single cookie value.

The problem is there can be multiple cookies with the same name for a
given document.  The YUI Cookie utility seems to assume there's only
one.  We could add a facility for filtering the results of getCookies,
but that's easy enough to do correctly in JavaScript.

Adam
Received on Wednesday, 24 February 2010 13:07:02 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:21 UTC