Open In App
Related Articles

HTML onoffline Event Attribute

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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.

HTML

<!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: 

aq

Output

Example 2:  

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

HTML

<!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:

az

Output

Supported Tags 

Supported Browsers

  • Google Chrome Not supported
  • Edge Not supported
  • Firefox Not supported
  • Opera Not supported
  • Safari 3 and above


Last Updated : 20 Dec, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads