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
{{ message }}
Repository navigation
Commit b94993a
Browse filesBrowse the repository at this point in the historyBrowse files
Remove "Cookie Options" concept and instead consistently use the "Cookie
Attributes" concept. My theory is that people think that "options" are
customized to the more convenient defaults, while attributes make it
clear they are just passed through to the cookie attributes in the
browser.
Add the default browser behavior in bold right below each attribute,
along with an example of how to create, read and remove.
// Need to use the same attributes (path, domain) as what the cookie was written with
65
+
// IMPORTANT!
66
+
// Need to use the same path, domain and secure attributes that were used when writing the cookie
66
67
Cookies.set('name', 'value', { path:'/' });
68
+
67
69
// This won't work!
68
70
Cookies.remove('name'); // => false
71
+
69
72
// This will work!
70
73
Cookies.remove('name', { path:'/' }); // => true
71
74
```
72
75
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.*
76
+
*Note: 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).*
74
77
75
78
## JSON
76
79
@@ -109,21 +112,37 @@ This project assumes [RFC 6265](http://tools.ietf.org/html/rfc6265#section-4.1.1
109
112
### Encoding
110
113
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.
111
114
112
-
## Cookie Options
115
+
## Cookie Attributes
113
116
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.
117
+
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
118
116
119
### expires
117
120
118
-
expires: 365
121
+
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.
122
+
123
+
**Browser default:** Removed when the user closes the browser.
119
124
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.
125
+
**Examples:**
126
+
127
+
```javascript
128
+
Cookies.set('name', 'value', { expires:365 });
129
+
Cookies.get('name'); // => 'value'
130
+
Cookies.remove('name');
131
+
```
121
132
122
133
### path
123
134
124
-
path: '/'
135
+
Define the path where the cookie is available.
136
+
137
+
**Browser default:** Path of the page where the cookie was created
125
138
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.
139
+
**Examples:**
140
+
141
+
```javascript
142
+
Cookies.set('name', 'value', { path:'/' });
143
+
Cookies.get('name'); // => 'value'
144
+
Cookies.remove('name', { path:'/' });
145
+
```
127
146
128
147
**Note regarding Internet Explorer:**
129
148
@@ -135,19 +154,34 @@ This means one cannot set a path using `path: window.location.pathname` in case
135
154
136
155
### domain
137
156
138
-
domain: 'example.com'
157
+
Define the domain where the cookie is available
158
+
159
+
**Browser default:** Domain of the page where the cookie was created
139
160
140
-
Define the domain where the cookie is valid. Default: domain of page where the cookie was created.
0 commit comments