ononline
The ononline event is triggered when the browser gains internet connectivity. It is the counterpart to the onoffline event.
ononline event
The ononline
event handler activates a script when the browser reconnects to the internet. It is helpful for alerting users about the restoration of their connection in web applications.
Syntax
In HTML
index.html
<element ononline="myScript">
In JS
script.js
object.ononline = myScript;
addEventListener()
function is used. In JavaScript, the
script.js
object.addEventListener("online", myScript);
Example
::event-ononline
::
index.html
<!DOCTYPE html>
<html>
<h1>HTML DOM Events</h1>
<h2>The ononline Event</h2>
<body ononline="onFunction()" onoffline="offFunction()">
<p><b>NOTE:</b> There will only be an "output" from this example when the browser shifts from offline to online.</p>
<p id="demo"></p>
<script>
function onFunction() {
document.getElementById("demo").innerHTML = "Your browser is working online.";
}
function offFunction() {
document.getElementById("demo").innerHTML = "Your browser is working offline.";
}
</script>
</body>
</html>
Values
Conclusion
The ononline
event is an important tool for detecting when a browser regains internet connectivity. It allows developers to notify users when their connection is restored, enhancing the user experience in web applications, especially in scenarios where users may be affected by network disruptions. By using this event alongside onoffline
, developers can create seamless, dynamic web applications that respond to changes in network status.