Open In App

HTML onoffline Event Attribute

The onoffline event attribute works when the browser works in offline mode. It is the opposite of ononline event attribute. It is activated when the device loses its internet connection. It is also useful for adapting the web application’s behavior when network connectivity is lost.

Note: The `onoffline` attribute is a direct opposite of the `ononline` attribute.



Syntax

<element onoffline = "script">

Attribute Value

The script event is run when onoffline attribute is called.

Example: 

 In this example, we will see the implementation of the above tag.






<!DOCTYPE html>
<html>
 
<head>
    <title>onoffline event attribute</title>
    <style>
        h1 {
            color:green;
        }
        body {
            text-align:center;
        }
    </style>
</head>
 
<body onoffline="gfg()">
    <h1>GeeksforGeeks</h1>
    <h2>onoffline Event Attribute</h2>
    <script>
        function gfg() {
            alert ("Browser working in offline mode");
        }
    </script>
</body>
 
</html>

Output: 

Output

Example 2:  

In this example, we will see the implementation of the above tag.




<!DOCTYPE html>
<html>
 
<head>
    <title>onoffline event attribute</title>
    <style>
        h1 {
            color: green;
        }
 
        body {
            text-align: center;
        }
    </style>
</head>
 
<body onoffline="gfg()">
    <h1>GeeksforGeeks</h1>
    <h2>onoffline Event Attribute</h2>
    <script>
        function gfg() {
            console.log("Browser working in offline mode");
        }
    </script>
</body>
 
</html>

Output:

Output

Supported Tags 

Supported Browsers


Article Tags :