ServiceWorkerContainer: sự kiện controllerchange
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
Sự kiện controllerchange của giao diện ServiceWorkerContainer được kích hoạt khi ServiceWorkerRegistration liên kết với tài liệu có được một worker active mới.
Cú pháp
Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc đặt một thuộc tính trình xử lý sự kiện.
js
addEventListener("controllerchange", (event) => { })
oncontrollerchange = (event) => { }
Loại sự kiện
Một Event chung.
Ví dụ
js
navigator.serviceWorker.addEventListener("controllerchange", () => {
console.log("The controller of current browsing context has changed.");
});
Đặc tả kỹ thuật
| Specification |
|---|
| Service Workers Nightly> # dom-serviceworkercontainer-oncontrollerchange> |