UnderZ

Javascript Library.

Cookies.

Read/Write/Delete document cookies.


Get all cookies

_z.cookie.get();

Returns: Object All cookies as Object

{ "cookie name" = "cookie value" }

Get one cookies

_z.cookie.get(name);

Returns: String cookie value Or “”


Add/Update cookies. (expire time by days)

_z.cookie.set(name, value, expire);

Returns: _z.cookie Object


Add/Update cookies (expire time by seconds)

_z.cookie.setBySec(name, value, expire);

Returns: _z.cookie Object


_z.cookie.delete(name);

Returns: _z.cookie Object

To delete all the cookies you can use:

_z.cookie.get().each( (x)=>_z.cookie.delete(x)&&x );

Examples

_z.cookie.set("user", "admin"); // cookie="user=admin" and expires when the browsing session ends
_z.cookie.set("pass", "123"); // cookie="user=admin; pass=123" and expires when the browsing session ends
_z.cookie.delete("pass"); // cookie="user=admin" and expires when the browsing session ends
_z.cookie.setBySec("pass", "123", 60); // cookie="user=admin;" and expires when the browsing session ends, cookie="pass=123" and expires after 60 seconds
_z.cookie.get("user"); // {user: "admin"}
_z.cookie.get(); // {user: "admin", pass: "123"}