# # Installation
Include Script *after* the JQuery library (unless you is packaging scripts somehow else):
"' HTML
<src= "/path/to/jquery.cookie.js"></script>
```
# # Usage
Create Session Cookie:
"' JavaScript
```
Create expiring Cookie, 7 days from then:
"' JavaScript
```
Create expiring cookie, valid across entire site:
"' JavaScript
$.cookie (' The_cookie ', ' The_value ', {expires:7, path: '/'});
```
Read Cookie:
"' JavaScript
//
```
Read All available cookies:
"' JavaScript
// = = {"The_cookie": "The_value", "... remaining": "Cookies"}
```
Delete Cookie:
"' JavaScript
$.removecookie (' The_cookie '); //
```
*note:when Deleting a cookie, must pass the exact same path, domain and secure options that were used to set the cook ie, unless you ' re relying on the default options that is.*
# # Configuration
# # RAW
By default of the cookie value is encoded/decoded when writing/reading, using ' encodeuricomponent '/' decodeuricomponent '. Bypass this by setting Raw to true:
"' JavaScript $.cookie.raw = true;
# # JSON
Turn on automatic storage of JSON objects passed as the cookie value. Assumes ' json.stringify ' and ' json.parse ':
"' JavaScript $.cookie.json = true;
# # Cookie Options
Cookie attributes can be set globally by setting properties of the ' $.cookie.defaults ' object or individually for each CAL L to ' $.cookie () ' By passing a plain object to the options argument. Per-call options override the default options.
# # Expires
expires:365
Define lifetime of the cookie. Value can be a ' number ' which'll be interpreted as the from time of creation or a ' Date ' object. If omitted, the cookie becomes a session cookie.
# # Path
path: '/'
Define the path where the cookie is valid. *by default the path of the cookie is the path of the page where the cookie was created (standard browser behavior). * If y ou want to make it available for instance across the entire domain use ' path: '/'. Default:path of page where the cookie was created.
**note regarding Internet explorer:**
> Due to a obscure bug in the underlying WinINET InternetGetCookie implementation, IE ' s document.cookie would not retur n a cookie If it is set with a path attribute containing a filename.
(from [Internet Explorer Cookie Internals (FAQ)] (http://blogs.msdn.com/b/ieinternals/archive/2009/08/20/ wininet-ie-cookie-internals-faq.aspx))
This means one cannot set a path using the ' path:window.location.pathname ' in case such pathname contains a filename like so: '/check.html ' (or at least, such cookie cannot is read correctly).
# # Domain
domain: ' example.com '
Define the domain where the cookie is valid. Default:domain of page where the cookie was created.
# # Secure
secure:true
If true, the cookie transmission requires a secure protocol (HTTPS). Default: ' false '.
# # Converters
Provide a conversion function as optional last argument for reading, in order to change the cookie's value to a different Representation on the fly.
Example for parsing a value into a number:
"' JavaScript $.cookie (' foo ', ' $.cookie '); (' foo ', number) ;//= 42"
Dealing with cookie that has been encoded using ' escape ' (3rd party Cookies):
"' JavaScript $.cookie.raw = true; $.cookie (' foo ', unescape);
You can pass an arbitrary conversion function.
# # Contributing
Check out the [contributing guidelines] (CONTRIBUTING.MD)
# # Authors
[Klaus Hartl] (HTTPS://GITHUB.COM/CARHARTL)
jquery.cookie_v1.4.1 Front-end auxiliary tools, cross-page record user's operating habits!