Home

Class goog.net.Cookies

A class for handling browser cookies.

Instance Method Summary
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.

containsKey(string key) ⇒ boolean

Returns whether there is a cookie with the given name.

containsValue(string value) ⇒ boolean

Returns whether there is a cookie with the given value. (This is an O(n) operation.)

get(string name, string= opt_default) ⇒ (string|undefined)

Returns the value for the first cookie with the given name.

getCookie_() ⇒ ?string

Private helper function to allow testing cookies without depending on the browser. IE6 can return null here.

getCount() ⇒ number
getKeyValues_() ⇒ ?Object

Gets the names and values for all the cookies.

getKeys() ⇒ ?Array

Gets the names for all the cookies.

getParts_() ⇒ !Array
getValues() ⇒ ?Array

Gets the values for all the cookies.

isEmpty() ⇒ boolean
isEnabled() ⇒ boolean

Returns true if cookies are enabled.

isNavigatorCookieEnabled_() ⇒ boolean

Returns navigator.cookieEnabled. Overridden in unit tests.

isValidName(string 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'

isValidValue(string 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.

remove(string name, string= opt_path, string= opt_domain) ⇒ boolean

Removes and expires a cookie.

set(string name, string value, number= opt_maxAge, ?string= opt_path, ?string= opt_domain, boolean= opt_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 {@code name} nor the {@code value} are encoded in any way. It is up to the callers of {@code get} and {@code set} (as well as all the other methods) to handle any possible encoding and decoding.

setCookie_(string s)

Private helper function to allow testing cookies without depending on the browser.