Navigator:credentials 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
Navigator
接口的只读属性 credentials
返回与当前文档关联的 CredentialsContainer
对象,该对象暴露用于请求凭据的方法。CredentialsContainer
接口还会在发生感兴趣的事件时通知用户代理,例如成功登录或注销。此接口可用于特性检测。
值
一个 CredentialsContainer
对象。
示例
js
if ("credentials" in navigator) {
navigator.credentials.get({ password: true }).then((creds) => {
// 使用凭据执行操作
});
} else {
// 使用之前的方式处理登录
}
规范
Specification |
---|
Credential Management Level 1 # framework-credential-management |
浏览器兼容性
BCD tables only load in the browser