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.
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:Â
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:
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
Share your thoughts in the comments
Please Login to comment...