Permissions

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2022.

* Some parts of this feature may have varying levels of support.

Note: This feature is available in Web Workers.

Giao diện Permissions của Permissions API cung cấp chức năng Permission API cốt lõi, chẳng hạn như các phương thức để truy vấn và thu hồi quyền.

Phương thức phiên bản

Permissions.query()

Trả về trạng thái quyền của người dùng cho một API đã cho.

Permissions.revoke() Đã lỗi thời

Thu hồi quyền hiện đang được đặt cho một API đã cho.

Ví dụ

js
navigator.permissions.query({ name: "geolocation" }).then((result) => {
  if (result.state === "granted") {
    showLocalNewsWithGeolocation();
  } else if (result.state === "prompt") {
    showButtonToEnableLocalNews();
  }
  // Không làm gì nếu quyền bị từ chối.
});

Thông số kỹ thuật

Thông số kỹ thuật
Permissions
# permissions-interface

Tương thích trình duyệt