onoffline Event

Definition and Usage

The onoffline event occurs when the browser starts to work offline.

Tip:onoffline Event with ononline Event Conversely.

Tip:You can also use navigator.onLine Property to determine whether the browser is in online or offline mode.

Example

Execute JavaScript when the browser starts to work offline:

<body onoffline="myFunction()">

Try It Yourself

Syntax

In HTML:

<element onoffline="myScript">

Try It Yourself

In JavaScript:

object.onoffline = function(){myScript};

Try It Yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("offline", myScript);

Try It Yourself

Note:Internet Explorer 8 or earlier versions do not support addEventListener() Method.

Technical Details

Bubbling: Not Supported
Cancellable: Not Supported
Event Type: Event
Supported HTML Tags: <body>
DOM Version: Level 3 Events

Browser Support

The numbers in the table indicate the first browser version that fully supports the event.

Events Chrome IE Firefox Safari Opera
onoffline Not Supported. Deprecated Since IE11
8.0
3.0 Not Supported Not Supported