Web Workers APIworker
The offline event of the WorkerGlobalScope fires when the device loses connection to the internet.
Syntax
Use the event name in EventTarget/addEventListener:
addEventListener("offline", (event) => { })
Alternatively, assign to the event handler property of the interface:
onoffline = (event) => { }
Event type
A generic Event.
Example
The following code snippet shows an onoffline handler set inside a worker (but note that this replaces other event listeners added using onoffline, if any):
self.onoffline = () => {
console.log("Your worker is now offline");
};
The same snippet, but using addEventListener():
self.addEventListener("offline", () => {
console.log("Your worker is now offline");
});
Specifications
Browser compatibility
See also
The WorkerGlobalScope interface it belongs to.
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
