JavaScript Network Events


1. online: This event occurs when the browser has gained access to the network and the value of navigator.onLine is switched to true.

Syntax:

    <element ononline=”functionName()”>


Example:

    <body ononline=”myScript()” >
    <script>
        function myScript()
        {
            alert(“Online”);
        }
    </script>        


2. offline: This event occurs when the browser has lost access to the network and the value of navigator.onLine switched to false.

Syntax:

    <element onoffline=”functionName()”>


Example:

    <body onoffline=”myScript()” >
    <script>
        function myScript()
        {
            alert(“Offline”);
        }
    </script>