In JavaScript, using the addEventListener()
method:
object.addEventListener("offline",
myScript);
This example uses the addEventListener()
method to attach a "online" and "offline" event to the window object.
Open the File menu and click on "Work Offline" to toggle between working online and offline.
The ononline and onoffline events are supported in Firefox.
<!DOCTYPE html> <html> <body> <p id="demo"></p> <script> window.addEventListener("online", onFunction); window.addEventListener("offline", offFunction); function onFunction() {/* www . ja v a 2 s . c o m*/ document.getElementById("demo").innerHTML = "Your browser is working online."; } function offFunction() { document.getElementById("demo").innerHTML = "Your browser is working offline."; } </script> </body> </html>
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
Supported HTML tags: | <body> |