Javascript DOM onoffline Event via HTML Tag onoffline function

Introduction

In JavaScript:

object.onoffline = 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 . j  a va 2s.com
  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>



PreviousNext

Related