--- title: Headers.delete() slug: Web/API/Headers/delete translation_of: Web/API/Headers/delete ---

{{APIRef("Fetch")}}{{ SeeCompatTable() }}

delete() 方法可以从Headers对象中删除指定header.

下列原因将会导致该方法抛出一个{{jsxref("TypeError")}}:

Note:出于安全原因, 部分头信息只能被用户代理控制. 这些头信息包括 {{Glossary("Forbidden_header_name", "forbidden header names", 1)}}  和 {{Glossary("Forbidden_response_header_name", "forbidden response header names", 1)}}.

Syntax

myHeaders.delete(name);

Parameters

name
需删除的HTTP header名称.

Returns

Void.

Example

创建一个空的Headers对象:

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

可以通过append()方法添加header:

myHeaders.append('Content-Type', 'image/jpeg');
myHeaders.get('Content-Type'); // Returns 'image/jpeg'

可以通过delete()方法删除已有header:

myHeaders.delete('Content-Type');
myHeaders.get('Content-Type'); // Returns null, as it has been deleted

Specifications

Specification Status Comment
{{SpecName('Fetch','#dom-headers-delete','delete()')}} {{Spec2('Fetch')}}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{ CompatChrome(42) }}
{{ CompatChrome(41) }} behind pref
 
{{ CompatGeckoDesktop(39)}}
34 behind pref
{{ CompatNo }}

29
28 behind pref

{{ CompatNo }}
Feature Android Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support {{ CompatNo }} {{ CompatNo }} {{ CompatNo }} {{ CompatNo }} {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}

See also