In JavaScript, using the addEventListener()
method:
object.addEventListener("online",
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() {//w ww. j av a 2s .c om 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> |
DOM Version: | Level 3 Events |