IdleDetector: requestPermission() static method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Phương thức tĩnh requestPermission() của giao diện IdleDetector trả về một Promise phân giải thành một chuỗi khi người dùng đã chọn có cấp quyền truy cập trạng thái rảnh rỗi cho nguồn gốc hay không. Phân giải thành "granted" nếu chấp nhận và "denied" nếu từ chối.
Cú pháp
IdleDetector.requestPermission()
Tham số
Không có.
Giá trị trả về
Một Promise phân giải thành "granted" hoặc "denied".
Bảo mật
Yêu cầu kích hoạt tạm thời của người dùng. Người dùng phải tương tác với trang hoặc phần tử giao diện để tính năng này hoạt động.
Ví dụ
Ví dụ dưới đây sử dụng sự kiện click trên nút để kích hoạt yêu cầu quyền phát hiện trạng thái rảnh rỗi của người dùng.
startButton.addEventListener("click", async () => {
if ((await IdleDetector.requestPermission()) !== "granted") {
console.error("Idle detection permission denied.");
return;
}
});
Thông số kỹ thuật
| Specification |
|---|
| Idle Detection API> # api-idledetector-requestpermission> |