The ononline attribute is an event handler on <body> (and frameset) for the window online event. It runs when the browser gains network access and Navigator.onLine switches to true.
Pair it with onoffline when the connection drops. Use online to clear banners, retry syncs, or refresh data — not to prove a specific website is reachable.
Baseline · Widely available.
Not deprecated and not experimental. Stable across modern browsers since about July 2015.
Online ≠ site reachable.
MDN: network problems or firewalls can still block your site even when the browser reports online. Still handle failed requests.
Syntax
HTML Syntax
syntax.html
<body ononline="script">
Modern equivalent: window.addEventListener("online", function () { … }); — listen on window, not with addEventListener on body alone.
Shows navigator.onLine right now. Use DevTools → Network → Offline, then turn it off to fire a real online event — or simulate events for practice (simulation does not flip onLine).
demo
Leave Offline mode in DevTools to fire a real online event, or use Simulate.
Connectivity
navigator.onLine: …
Last event: (none)
Code
HTML Examples
Short study snippets. Test with DevTools Offline (then reconnect), or use Try It Yourself.
Example 1 — Update Status on body
Show a message when the browser reports online again.
HTML
<body ononline="setStatus('You are online')">
<p id="status">Waiting…</p>
<p>Go Offline in DevTools, then turn Offline off to test.</p>
<script>
function setStatus(text) {
document.getElementById("status").textContent = text;
}
</script>
</body>
Prefer this style in apps so multiple handlers can coexist.
Edge Cases & Pitfalls
Most bugs treat “browser says online” as “my API is reachable.”
reach
Online does not mean your site works
MDN: firewalls or partial outages can still block requests. Retry carefully and surface real errors.
hint
onLine is a heuristic
LAN without Internet, VPNs, and OS checks can misreport. Use events as UX signals, not hard gates.
listen
addEventListener belongs on window
HTML attribute goes on body. Script listeners must use window — not body.addEventListener alone.
load
Already online at start
online fires on a change to online. If the page loads already online, check navigator.onLine once yourself.
pair
Always pair with offline
Show warnings in onoffline; clear them and retry in ononline.
Compatibility
Browser Support
ononline is an HTML event handler for the window online event. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
ononline
Widely available since about July 2015. Supported across modern browsers; remember Navigator.onLine heuristics still vary by OS.
98%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetModern
Full support
Internet ExplorerLegacy support
Supported
ononlineWidely supported
Bottom line: Safe to use for “back online” UX. Prefer addEventListener on window in apps; always verify important requests succeed.
Remember
Key Takeaways
Role: run script when the browser reports network access restored.
HTML: put ononline on body; scripts listen on window.
Pair: use onoffline when connectivity drops.
Caution: online ≠ your website is reachable — still handle errors.
One line: use ononline to resume and retry — then confirm the request actually succeeds.
Frequently Asked Questions
It is an event handler (usually on body) for the window online event. The browser runs your script when it gains network access and Navigator.onLine switches to true.
ononline runs when connectivity returns. onoffline runs when the connection is lost and Navigator.onLine becomes false.
No. MDN: do not use this event to decide if a particular site is available. Firewalls or network problems can still block requests even when the browser reports online.
Put the HTML attribute on body (or frameset). For addEventListener, listen on window. Listening only on body with addEventListener will not receive the event.
Enable DevTools → Network → Offline, then turn Offline off again. That fires offline then online. You can also dispatch a synthetic online Event for demos.
No. The online event is Baseline widely available. Prefer window.addEventListener("online", …) in modern scripts; the body attribute is the HTML form of the same handler.