credentialsRequest接口的只读属性,用于表示用户代理是否应该在跨域请求的情况下从其他域发送cookies。这与XHR的withCredentials 标志相似,不同的是有三个可选值(后者是两个):

  • omit: 从不发送cookies.
  • same-origin: 只有当URL与响应脚本同源才发送 cookies、 HTTP Basic authentication 等验证信息.
  • include: 不论是不是跨域的请求,总是发送请求资源域在本地的 cookies、 HTTP Basic authentication 等验证信息.

语法

var myCred = request.credentials;

Value

A RequestCredentials value.

举例

在以下代码中,我们使用Request.Request()创建了一个新的request(为了一个与脚本在同一目录下的图片文件), 接着将request credentials存入一个变量:

var myRequest = new Request('flowers.jpg');
var myCred = myRequest.credentials; // returns "omit" by default

说明

Specification Status Comment
Fetch
credentials
Living Standard Initial definition

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support

42

411

Yes

39

342

No

29

283

No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support No42 — 46 Yes No No No4.0

1. From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.

2. From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.

3. From version 28: this feature is behind the Experimental Web Platform Features preference.

See also

文档标签和贡献者

标签: 
此页面的贡献者: lichao, Maxpsc
最后编辑者: lichao,