WakeLockSentinel: release event

Baseline 2025
Newly available

Since March 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Sự kiện release của giao diện WakeLockSentinel được kích hoạt khi handle của đối tượng sentinel đã được giải phóng.

Một WakeLockSentinel có thể được giải phóng thủ công qua phương thức release(), hoặc tự động qua khóa thức nền tảng. Điều này có thể xảy ra nếu tài liệu trở nên không hoạt động hoặc mất tầm nhìn, nếu thiết bị yếu pin hoặc người dùng bật chế độ tiết kiệm điện.

Cú pháp

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

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

onrelease = (event) => { }

Loại sự kiện

Một Event chung.

Ví dụ

Ví dụ này cập nhật UI nếu khóa thức được giải phóng.

js
wakeLock.addEventListener("release", () => {
  // if wake lock is released alter the UI accordingly
  statusElement.textContent = "Wake Lock has been released";
});

Thông số kỹ thuật

Thông số kỹ thuật
Screen Wake Lock API
# the-onrelease-attribute

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

Xem thêm