Events
ononline
The browser reports a return to an online connectivity state. Window event handler, exposed through the body element in HTML; register on window rather than on an arbitrary element. Event interface: Event. For the described native event: bubbles: no; cancelable: no. Retry queued work cautiously; this does not prove that a particular server is reachable. Example: Change browser network state; delivery varies. The event listener is registered with addEventListener(), which avoids inline script handlers and supports multiple listeners. Inline handlers require a CSP that permits them; do not insert untrusted code into handler attributes.
Formal Syntax & Structure
html syntaxhtml
<body ononline="handleEvent(event)"> window.addEventListener("online", event => { /* handle event */ });Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| ononline | JavaScript handler body | Optional HTML event-handler code; the example uses a registered listener instead. Not a Boolean attribute. |
| event | Event | Event object delivered to the addEventListener callback; event.type is "online". Inspect target, currentTarget, bubbles and cancelable as appropriate. |
Working Example
Example Snippethtml
<p>Window event monitor</p><p role="status" id="log">Waiting for online</p><script> const target = window; const log = document.getElementById("log"); target.addEventListener("online", event => { log.textContent = String("Online hint: " + navigator.onLine); });</script>