Horje
HTML onoffline Event Attribute

Definition and Usage

The onoffline attribute fires when the browser's connection status changes from online to offline.

Tip: The onoffline attribute is the opposite of the ononline attribute.


Browser Support

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

Syntax

<element onoffline="script">

Attribute Values

Value Description
script The script to be run on onoffline

Technical Details

Supported HTML tags: <body>

Example of HTML onoffline Event Attribute

Here executes a JavaScript when the browser changes from working online to working offline.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body ononline="onFunction()" onoffline="offFunction()">

<p>Try to disconnect from the internet to toggle between working online and offline.</p>

<script>
function onFunction() {
  alert ("Your browser is working online.");
}

function offFunction() {
  alert ("Your browser is working offline.");
}
</script>

</body>
</html>

Output should be:

How to add a JavaScript when the browser changes from working online to working offline

Try to disconnect from the internet to toggle between working online and offline.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body ononline="onFunction()" onoffline="offFunction()">

<p>Try to disconnect from the internet to toggle between working online and offline.</p>

<script>
function onFunction() {
  alert ("Your browser is working online.");
}

function offFunction() {
  alert ("Your browser is working offline.");
}
</script>

</body>
</html>

Output should be:

How to add a JavaScript when the browser changes from working online to working offline




html event attributes

Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Window Event Attributes
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference