Document.hasStorageAccess()

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

Document的**hasStorageAccess()** 方法返回了一个Promise来判断该文档是否有访问第一方储存的权限。

通过 Storage Access API (en-US) 获取更多信息。

语法

var promise = document.hasStorageAccess();

参数

None.

返回值

一个用来判断文档是否有权利访问其第一方存储的Promise

If the promise gets resolved and a user gesture event was being processed when the function was originally called, the resolve handler will run as if a user gesture was being processed, so it will be able to call APIs that require user activation.

Examples

js

document.hasStorageAccess().then((hasAccess) => {
  if (hasAccess) {
    // storage access has been granted already.
  } else {
    // storage access hasn't been granted already;
    // you may want to call requestStorageAccess().
  }
});

Specifications

The API is currently only at the proposal stage — the standardization process has yet to begin. You can currently find specification details of the API at Apple's Introducing Storage Access API blog post, and WHATWG HTML issue 3338 — Proposal: Storage Access API.

Browser compatibility

BCD tables only load in the browser

See also