You are here: Reference > JavaScript > client-side > event handling > events > onoffline

onoffline event | offline event

Browser support:
83
Occurs when the browser starts to work offline.
Note: The onoffline event is supported in Internet Explorer from version 8 and in Firefox from version 3.
You can switch between working online and offline with the Work Offline menu item under the File menu in Internet Explorer and Firefox.
The onoffline event only occurs if the browser is working online and it starts to work offline. The onoffline event does not fire during the page load regardless that the browser is working offline.

You can get whether the browser is working online or offline with the onLine property. If you need to detect when the browser starts to work online, use the ononline event.

How to register:

In HTML:
<ELEMENT onoffline="handler">
83

In JavaScript:
object.onoffline = handler;
83
object.addEventListener ("offline", handler, useCapture);
93
object.attachEvent ("onoffline", handler);
8
You can find the related objects in the Supported by objects section below.
The event object is accessible to all event handlers in all browsers. The properties of the event object contain additional information about the current event. To get further details about these properties and the possible event handler registration methods, please see the page for the event object.
For a complete list of events, see the page for Events in JavaScript.

Basic information:

Bubbles No
Cancelable No
Event object Event

Actions that invoke the onoffline event:

  • Setting the browser to work offline with the Work Offline menu item under the File menu.

Example HTML code 1:

This example illustrates the use of the ononline and onoffline events and the onLine property:
<head>
    <script type="text/javascript">
        function OnLoad () {
            if ('onLine' in navigator) {
                if (navigator.onLine) {
                    alert ("Your browser is working online.");
                }
                else {
                    alert ("Your browser is working offline.");
                }
            }
            else {
                alert ("Your browser does not support the onLine property.");
            }
        }

        function OnOnline () {
            alert ("Your browser starts to work online.");
        }
        function OnOffline () {
            alert ("Your browser starts to work offline.");
        }
    </script>
</head>
<body onload="OnLoad ()" ononline="OnOnline ();" onoffline="OnOffline ();" >
    Please click on the Work Offline menu item under the File menu to switch between working online and offline.
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content