You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Need to use the same attributes (path, domain) as what the cookie was written with
65
+
// Need to use the same path, domain and secure attributes that were used when writing the cookie
66
66
Cookies.set('name', 'value', { path:'/' });
67
-
// This won't work!
68
-
Cookies.remove('name'); // => false
69
-
// This will work!
70
-
Cookies.remove('name', { path:'/' }); // => true
67
+
Cookies.remove('name'); // fail!
68
+
Cookies.remove('name', { path:'/' }); // removed!
71
69
```
72
70
73
-
*Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie, unless you're relying on the default options that is.*
71
+
*IMPORTANT! when deleting a cookie, you must pass the exact same path, domain and secure attributes that were used to set the cookie, unless you're relying on the [default attributes](#cookie-attributes).*
This project assumes [RFC 6265](http://tools.ietf.org/html/rfc6265#section-4.1.1) as a reference for everything. That said, some custom rules are applied in order to provide robustness and cross-browser compatibility.
105
+
This project is [RFC 6265](http://tools.ietf.org/html/rfc6265#section-4.1.1) compliant.
106
+
However, all special characters that are not allowed in the cookie-value or cookie-name are encoded/decoded with each UTF-8 Hex equivalent. Special characters that consistently work among all supported browsers are not encoded/decoded this way.
108
107
109
-
### Encoding
110
-
All special characters that are not allowed in the cookie-value or cookie-name in at least one supported browser are encoded/decoded with each UTF-8 Hex equivalent. Special characters that consistently work among all supported browsers are not encoded/decoded this way.
108
+
## Cookie Attributes
111
109
112
-
## Cookie Options
113
-
114
-
Cookie attributes can be set globally by setting properties of the `Cookies.defaults` object or individually for each call to `Cookies.set()` by passing a plain object to the options argument. Per-call options override the default options.
110
+
Cookie attributes defaults can be set globally by setting properties of the `Cookies.defaults` object or individually for each call to `Cookies.set(...)` by passing a plain object in the last argument. Per-call attributes override the default attributes.
115
111
116
112
### expires
117
113
118
-
expires: 365
114
+
Define when the cookie will be removed. Value can be a `Number` which will be interpreted as days from time of creation or a `Date` instance. If omitted, the cookie becomes a session cookie.
115
+
116
+
**Browser default:** Cookie is removed when the user closes the browser.
117
+
118
+
**Examples:**
119
119
120
-
Define lifetime of the cookie. Value can be a `Number` which will be interpreted as days from time of creation or a `Date` object. If omitted, the cookie becomes a session cookie.
120
+
```javascript
121
+
Cookies.set('name', 'value', { expires:365 });
122
+
Cookies.get('name'); // => 'value'
123
+
Cookies.remove('name');
124
+
```
121
125
122
126
### path
123
127
124
-
path: '/'
128
+
Define the path where the cookie is available.
129
+
130
+
**Browser default:** Path of the page where the cookie was created
131
+
132
+
**Examples:**
125
133
126
-
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 you want to make it available for instance across the entire domain use `path: '/'`. Default: path of page where the cookie was created.
134
+
```javascript
135
+
Cookies.set('name', 'value', { path:'/' });
136
+
Cookies.get('name'); // => 'value'
137
+
Cookies.remove('name', { path:'/' });
138
+
```
127
139
128
140
**Note regarding Internet Explorer:**
129
141
@@ -135,19 +147,34 @@ This means one cannot set a path using `path: window.location.pathname` in case
135
147
136
148
### domain
137
149
138
-
domain: 'example.com'
150
+
Define the domain where the cookie is available
151
+
152
+
**Browser default:** Domain of the page where the cookie was created
139
153
140
-
Define the domain where the cookie is valid. Default: domain of page where the cookie was created.
0 commit comments