credentials
只读特性在
Request
interface indicates whether the user agent should send cookies from the other domain in the case of cross-origin requests.
var myCred = request.credentials;
A
RequestCredentials
dictionary value indicating whether the user agent should send cookies from the other domain in the case of cross-origin requests. Possible values are:
omit
: Never send or receive cookies.
same-origin
: Send user credentials (cookies, basic http auth, etc..) if the URL is on the same origin as the calling script.
This is the default value.
包括
: Always send user credentials (cookies, basic http auth, etc..), even for cross-origin calls.
This is similar to XHR’s
withCredentials
flag, but with three available values instead of two.
In the following snippet, we create a new request using the
Request.Request()
constructor (for an image file in the same directory as the script), then save the request credentials in a variable:
var myRequest = new Request('flowers.jpg');
var myCred = myRequest.credentials; // returns "same-origin" by default
| 规范 | 状态 | 注释 |
|---|---|---|
|
Fetch
The definition of 'credentials' in that specification. |
实时标准 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
credentials
|
Chrome
42
|
Edge 14 |
Firefox
39
|
IE No |
Opera
29
|
Safari 10.1 | WebView Android 42 | Chrome Android 42 | Firefox Android Yes |
Opera Android
29
|
Safari iOS 10.3 | Samsung Internet Android 4.0 |
默认值
same-origin
|
Chrome 72 | Edge 18 | Firefox 61 | IE No | Opera 55 | Safari 12.1 | WebView Android 72 | Chrome Android 72 | Firefox Android Yes | Opera Android No | Safari iOS 12.2 | Samsung Internet Android 11.0 |
完整支持
不支持
实验。期望将来行为有所改变。
用户必须明确启用此特征。