File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -342,7 +342,7 @@ document.cookie = "foo=bar; expires=Fri, 31 Dec 2020 23:59:59 GMT";
342
342
各个属性的写入注意点如下。
343
343
344
344
- ` path ` 属性必须为绝对路径,默认为当前路径。
345
- - ` domain ` 属性值必须是当前发送 Cookie 的域名的一部分。比如,当前域名是` example.com ` ,就不能将其设为` foo.com ` 。该属性默认为当前的一级域名(不含二级域名)。
345
+ - ` domain ` 属性值必须是当前发送 Cookie 的域名的一部分。比如,当前域名是` example.com ` ,就不能将其设为` foo.com ` 。该属性默认为当前的一级域名(不含二级域名)。如果显式设置该属性,则该域名的任意子域名也可以读取 Cookie。
346
346
- ` max-age ` 属性的值为秒数。
347
347
- ` expires ` 属性的值为 UTC 格式,可以使用` Date.prototype.toUTCString() ` 进行日期格式转换。
348
348
@@ -352,9 +352,11 @@ document.cookie = "foo=bar; expires=Fri, 31 Dec 2020 23:59:59 GMT";
352
352
document .cookie = ' fontSize=14; '
353
353
+ ' expires=' + someDate .toGMTString () + ' ; '
354
354
+ ' path=/subdirectory; '
355
- + ' domain=. example.com' ;
355
+ + ' domain=example.com' ;
356
356
```
357
357
358
+ 注意,上面的` domain ` 属性,以前的写法是` .example.com ` ,表示子域名也可以读取该 Cookie,新的写法可以省略前面的点。
359
+
358
360
Cookie 的属性一旦设置完成,就没有办法读取这些属性的值。
359
361
360
362
删除一个现存 Cookie 的唯一方法,是设置它的` expires ` 属性为一个过去的日期。
You can’t perform that action at this time.
0 commit comments