From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/headers/has/index.html | 127 +++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 files/zh-cn/web/api/headers/has/index.html (limited to 'files/zh-cn/web/api/headers/has/index.html') diff --git a/files/zh-cn/web/api/headers/has/index.html b/files/zh-cn/web/api/headers/has/index.html new file mode 100644 index 0000000000..471bd1fb90 --- /dev/null +++ b/files/zh-cn/web/api/headers/has/index.html @@ -0,0 +1,127 @@ +--- +title: Headers.has() +slug: Web/API/Headers/has +translation_of: Web/API/Headers/has +--- +
{{APIRef("Fetch")}}
+ +

{{domxref("Headers")}} 接口的 has()方法返回一个布尔值来声明一个 Headers对象 是否包含特定的头信息.

+ +

考虑到安全因素, 一些头信息只能被user agent来管理. 这些头信息包括{{Glossary("Forbidden_header_name", "forbidden header names", 1)}}  和{{Glossary("Forbidden_response_header_name", "forbidden response header names", 1)}}.

+ +

Syntax

+ +
myHeaders.has(name);
+ +

Parameters

+ +
+
name
+
你要测试的HTTP头字段的名称。如果给出的名称不在HTTP头中,将爬出异常{{jsxref("TypeError")}}。
+
+ +

Returns

+ +

A {{domxref("Boolean")}}.

+ +

Example

+ +

创建一个空的Headers对象是简单的:

+ +
var myHeaders = new Headers(); // Currently empty
+ +

你可以使用{{domxref("Headers.append")}}来向myHeaders添加一个头信息, 然后使用 has()方法来测试是否添加成功:

+ +
myHeaders.append('Content-Type', 'image/jpeg');
+myHeaders.has('Content-Type'); // Returns true
+myHeaders.has('Accept-Encoding'); // Returns false
+
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Fetch','#dom-headers-has','has()')}}{{Spec2('Fetch')}} 
+ +

Browser compatibility

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{ CompatChrome(42) }}
+ {{ CompatChrome(41) }} behind pref
+  
{{CompatVersionUnknown}}{{ CompatGeckoDesktop(39)}}
+ 34 behind pref
{{ CompatNo }} +

29
+ 28 behind pref

+
{{ CompatNo }}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidEdgeFirefox Mobile (Gecko)Firefox OS (Gecko)IE PhoneOpera MobileSafari MobileChrome for Android
Basic support{{ CompatNo }}{{CompatVersionUnknown}}{{ CompatNo }}{{ CompatNo }}{{ CompatNo }}{{ CompatNo }}{{ CompatNo }}{{ CompatNo }}
+
+ +

See also

+ + -- cgit v1.2.3-54-g00ecf