--- title: credentials slug: Web/API/Navigator/credentials translation_of: Web/API/Navigator/credentials ---

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

{{domxref("Navigator")}}接口的credentials属性返回{{domxref("CredentialsContainer")}}接口,该接口暴露了请求凭证的方法。 {{domxref("CredentialsContainer")}}接口还会在下相关事件发生时通知用户,例如登录或注销成功。该接口可用于特征检测。

语法

var credentialsContainer = navigator.credentials

返回值

{{domxref("CredentialsContainer")}} 接口.

示例

if ('credentials' in navigator) {
  navigator.credentials.get({password: true})
  .then(function(creds) {
    //Do something with the credentials.
  });
} else {
  //Handle sign-in the way you did before.
};

Specifications

Specification Status Comment
{{SpecName('Credential Management')}} {{Spec2('Credential Management')}} Initial definition.

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(51.0)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatNo}} {{CompatChrome(51.0)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatChrome(51.0)}}