Javascript DOM ononline Event via ononline function

Introduction

In JavaScript:

object.ononline = function(){
       myScript};

This example uses the HTML DOM to assign an "ononline" and "onoffline" event to a body element.

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.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementsByTagName("BODY")[0].ononline = function() {onFunction()};
document.getElementsByTagName("BODY")[0].onoffline = function() {offFunction()};

function onFunction() {//w  w w.  java2s . 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>
DOM Version: Level 3 Events



PreviousNext

Related