非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。
PasswordCredential
构造函数创建新
PasswordCredential
对象。
In supporting browsers, an instance of this class may be passed the
credential
从
init
object for global
fetch
.
var myCredential = new PasswordCredential(passwordCredentialData) var myCredential = new PasswordCredential(HTMLFormElement)
Either of the following:
iconURL
: (Optional) the URL of a user's avatar image.
id
: The ID of the user signing in.
名称
: (Optional) The name of the user signing in.
password
: The password of the user signing in.
HTMLFormElement
with appropriate input fields. The form should, at the very least, contain an id and password. It could also require a CSRF token.
This example shows how to set up an
HTMLFormElement
to caputure data which we'll use to create a
PasswordCredential
对象。
Starting with the form element.
<form id="form" method="post"> <input type="text" name="id" autocomplete="username" /> <input type="password" name="password" autocomplete="current-password" /> <input type="hidden" name="csrf_token" value="*****" /> </form>
Then, a reference to this form element, using it to create a
PasswordCredential
object, and storing it in the browser's password system.
var form = document.querySelector('#form');
var creds = new PasswordCredential(form);
// Store the credentials.
navigator.credentials.store(creds)
.then(function(creds) {
// Do something with the credentials if you need to.
});
| 规范 | 状态 | 注释 |
|---|---|---|
| Credential Management Level 1 | 工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
PasswordCredential()
构造函数
非标
|
Chrome 51 | Edge ≤79 | Firefox ? | IE ? | Opera ? | Safari ? | WebView Android 51 | Chrome Android 51 | Firefox Android ? | Opera Android ? | Safari iOS ? | Samsung Internet Android 5.0 |
完整支持
兼容性未知
非标。预期跨浏览器支持较差。
PasswordCredential
PasswordCredential