net.Cookies Extends
A class for handling browser cookies.

Inheritance

Constructor

goog.net.Cookies(context)

Parameters

context : Document
The context document to get/set cookies on.

Instance Methods

Public Protected Private
clear()
Removes all cookies for this document. Note that this will only remove cookies from the current path and domain. If there are cookies set using a subpath and/or another domain these will still be there.
code »
containsKey(key) boolean
Returns whether there is a cookie with the given name.
Arguments:
key : string
The name of the cookie to test for.
Returns: boolean  Whether there is a cookie by that name.
code »
containsValue(value) boolean
Returns whether there is a cookie with the given value. (This is an O(n) operation.)
Arguments:
value : string
The value to check for.
Returns: boolean  Whether there is a cookie with that value.
code »
get(nameopt_default) string | undefined
Returns the value for the first cookie with the given name.
Arguments:
name : string
The name of the cookie to get.
opt_default : string=
If not found this is returned instead.
Returns: string | undefined  The value of the cookie. If no cookie is set this returns opt_default or undefined if opt_default is not provided.
code »
getCookie_() string
Private helper function to allow testing cookies without depending on the browser. IE6 can return null here.
Returns: string  Returns the document.cookie.
code »
getCount() number
No description.
Returns: number  The number of cookies for this document.
code »
getKeyValues_() !Object
Gets the names and values for all the cookies.
Returns: !Object  An object with keys and values.
code »
getKeys() Array.<string>
Gets the names for all the cookies.
Returns: Array.<string>  An array with the names of the cookies.
code »
getParts_() !Array.<string>
No description.
Returns: !Array.<string>  The cookie split on semi colons.
code »
getValues() Array.<string>
Gets the values for all the cookies.
Returns: Array.<string>  An array with the values of the cookies.
code »
isEmpty() boolean
No description.
Returns: boolean  Whether there are any cookies for this document.
code »
isEnabled() boolean
Returns true if cookies are enabled.
Returns: boolean  True if cookies are enabled.
code »
isValidName(name) boolean
We do not allow '=', ';', or white space in the name. NOTE: The following are allowed by this method, but should be avoided for cookies handled by the server. - any name starting with '$' - 'Comment' - 'Domain' - 'Expires' - 'Max-Age' - 'Path' - 'Secure' - 'Version'
Arguments:
name : string
Cookie name.
Returns: boolean  Whether name is valid.
code »
isValidValue(value) boolean
We do not allow ';' or line break in the value. Spec does not mention any illegal characters, but in practice semi-colons break parsing and line breaks truncate the name.
Arguments:
value : string
Cookie value.
Returns: boolean  Whether value is valid.
code »
remove(nameopt_pathopt_domain) boolean
Removes and expires a cookie.
Arguments:
name : string
The cookie name.
opt_path : string=
The path of the cookie, or null to expire a cookie set at the full request path. If not provided, the default is '/' (i.e. path=/).
opt_domain : string=
The domain of the cookie, or null to expire a cookie set at the full request host name. If not provided, the default is null (i.e. cookie at full request host name).
Returns: boolean  Whether the cookie existed before it was removed.
code »
set(namevalueopt_maxAgeopt_pathopt_domainopt_secure)
Sets a cookie. The max_age can be -1 to set a session cookie. To remove and expire cookies, use remove() instead. Neither the name nor the value are encoded in any way. It is up to the callers of get and set (as well as all the other methods) to handle any possible encoding and decoding.
Arguments:
name : string
The cookie name.
value : string
The cookie value.
opt_maxAge : number=
The max age in seconds (from now). Use -1 to set a session cookie. If not provided, the default is -1 (i.e. set a session cookie).
opt_path : ?string=
The path of the cookie. If not present then this uses the full request path.
opt_domain : ?string=
The domain of the cookie, or null to not specify a domain attribute (browser will use the full request host name). If not provided, the default is null (i.e. let browser use full request host name).
opt_secure : boolean=
Whether the cookie should only be sent over a secure channel.
code »
setCookie_(s)
Private helper function to allow testing cookies without depending on the browser.
Arguments:
s : string
The cookie string to set.
code »

Instance Properties

document_ :
The context document to get/set cookies on
Code »

Static Properties

goog.net.Cookies.MAX_COOKIE_LENGTH :
Static constant for the size of cookies. Per the spec, there's a 4K limit to the size of a cookie. To make sure users can't break this limit, we should truncate long cookies at 3950 bytes, to be extra careful with dumb browsers/proxies that interpret 4K as 4000 rather than 4096.
Code »
goog.net.Cookies.SPLIT_RE_ :
RegExp used to split the cookies string.
Code »

Package net

Package Reference