IdleDetector: change event

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.

Note: This feature is available in Dedicated Web Workers.

Sự kiện change của giao diện IdleDetector được kích hoạt khi giá trị của userState hoặc screenState thay đổi.

Cú pháp

Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc thiết lập thuộc tính trình xử lý sự kiện.

js
addEventListener("change", (event) => { })

onchange = (event) => { }

Loại sự kiện

Một Event thông thường.

Ví dụ

Trong ví dụ dưới đây, callback change in trạng thái của userStatescreenState ra console.

js
idleDetector.addEventListener("change", () => {
  const userState = idleDetector.userState;
  const screenState = idleDetector.screenState;
  console.log(`Idle change: ${userState}, ${screenState}.`);
});

Thông số kỹ thuật

Specification
Idle Detection API
# api-idledetector-onchange

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