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

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.

What do you think of this?

--
Christian Schmidt

Reply via email to