blob: 033531f4a44b3c291a58858b451485ed10e55a0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
---
title: Navigator.cookieEnabled
slug: Web/API/Navigator/cookieEnabled
tags:
- API
- DOM
- cookie
- 属性
translation_of: Web/API/Navigator/cookieEnabled
---
<p>{{ ApiRef("HTML DOM") }}</p>
<p><code>navigator.cookieEnabled</code> 返回一个布尔值,来表示当前页面是否启用了 cookie。本属性为只读属性。</p>
<h2 id="语法" name="语法">语法</h2>
<pre class="brush: js">let cookieEnabled = navigator.cookieEnabled;
</pre>
<ul>
<li><code>cookieEnabled</code> 是个<a href="/zh-CN/docs/Glossary/Boolean">布尔值</a>: <code>true</code> 或 <code>false</code>。</li>
</ul>
<h2 id="示例">示例</h2>
<pre class="brush: js">if (!navigator.cookieEnabled) {
// 浏览器不支持 cookie,或者用户禁用了 cookie。
}
</pre>
<h2 id="标准">标准</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">标准</th>
<th scope="col">状态</th>
<th scope="col">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName("HTML WHATWG", "webappapis.html#dom-navigator-cookieenabled", "Navigator.cookieEnabled")}}</td>
<td>{{Spec2("HTML WHATWG")}}</td>
<td>初次定义</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("api.Navigator.cookieEnabled")}}</p>
|