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

[whatwg] Suggestion: API for accessing cookies (document.cookies)

From: Ian Hickson <ian@hixie.ch>
Date: Sat, 9 Feb 2008 05:00:43 +0000 (UTC)
Message-ID: <Pine.LNX.4.62.0802090453130.20115@hixie.dreamhostps.com>
On Fri, 28 Dec 2007, Christian Schmidt wrote:
>
> In order to read, write and delete cookies from script most people use 
> their own utility functions like the ones shown at 
> http://www.w3schools.com/js/js_cookies.asp

Indeed. I think though that at this point this is well enough understood 
that it's not really worth changing the API -- people will have to support 
the old one for years anyway.


> It would be useful if cookies could be read, written and deleted through 
> a more abstract API, e.g. by an HTMLCollection-like interface stored in 
> document.cookies. This would allow something like this:
> 
> if (document.cookies.myCookie) {
> 	alert(document.cookies.myCookie.value)
> 
> 	document.cookies.remove('myCookie');
> 	// or alternatively
> 	document.cookies.myCookie.remove();
> 
> 	document.cookies.add('myCookie2', 'myVal', '/', 'example.org');
> }
> 
> In particular the remove() method would be useful, because today neither 
> the client-side nor the server-side can determine the path and domain 
> parameters necessary to delete a given cookie unless they know how it 
> was originally set.
>
> The API could give access to the values only or possibly also to the 
> other properties (expiry, path etc.) that are currenly not accessible 
> from neither client-side nor server-side.

Well, the DOM storage API and the SQL APIs provide a better API than 
cookies, but of course that data isn't sent over the network. A library 
could be made to interface them, though.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Friday, 8 February 2008 21:00:43 UTC

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