goog.net.Cookies
Provided By | |
---|---|
All Known Aliases |
A class for handling browser cookies.
new Cookies( context )
Parameters |
|
---|
Instance Methods
this.clear() → void
void
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.
this.containsKey( key ) → boolean
boolean
this.containsValue( value ) → boolean
boolean
this.get( name, opt_default ) → (string|undefined)
(string|undefined)
Returns the value for the first cookie with the given name.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
this.getCount() → number
number
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.isEmpty() → boolean
boolean
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.isEnabled() → boolean
boolean
Returns true if cookies are enabled.
navigator.cookieEnabled is an unreliable API in some browsers such as Internet Explorer. It will return true even when cookies are actually blocked. To work around this, check for the presence of cookies, or attempt to manually set and retrieve a cookie, which is the ultimate test of whether or not a browser supports cookies.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.isValidName( name ) → boolean
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'
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
| ||||
See Also |
this.isValidValue( value ) → boolean
boolean
this.remove( name, opt_path, opt_domain ) → boolean
boolean
Removes and expires a cookie.
Parameters |
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
this.set( name, value, options ) → void
void
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.
Parameters |
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Throws |
|
Static Functions
Cookies.getInstance() → goog.net.Cookies
goog.net.Cookies
Getter for the static instance of goog.net.Cookies.
Parameters | None. | |
---|---|---|
Returns |
|
Static Properties
Cookies.MAX_COOKIE_LENGTH → number
number
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.