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