HTML ononline Event Attribute


The HTML ononline event attribute is triggered when the browser starts to work online.

Syntax

Following is the syntax −

<tagname ononline=”script”></tagname>

Let us see an example of HTML ononline event Attribute−

Example

 Live Demo

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      height: 100vh;
      background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
      text-align: center;
   }
   .show {
      font-size: 1.2rem;
      color: #fff;
   }
</style>
<body ononline="onlineFn()" onoffline="offlineFn()">
<h1>HTML onoffline/ononline Event Attribute Demo</h1>
<p style="color:#db133a;">Try to disable/enable your network.</p>
<div class="show"></div>
<script>
   function onlineFn() {
      alert("Hey! You are online");
   }
   function offlineFn() {
      alert("Hey! You are offline");
   }
</script>
</body>
</html>

Output

Now try to enable/disable your network to observe how onoffline/ononline event attribute works−

Updated on: 27-Sep-2019

57 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements