HTML onoffline Event Attribute

Description

The event attribute onoffline occurs when the browser goes offline (when disconnected from the Internet). It can be used to alert the user that the Internet connection has been lost, or to disable some functions. These features must be enabled using the ononline attribute.

Syntax

<element onoffline="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE HTML>
<html>
<html>
<body ononline="onFunction()" onoffline="offFunction()">

<p>Open the File menu and click on the “Work offline” button to switch between working on onlie and offline.</p>

<p><strong>Note:</strong>Ononline and onoffline events are supported only in Firefox and Internet Explorer from versions 8 to 10.</p>

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

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

</body>
</html>

Supported Tags

<body>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
??????
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
??????