Execute a script when the browser starts to work online in HTML?


When the web browser starts to work online, the ononline attribute triggers. You can try to run the following code to implement ononline attribute −

Example

<!DOCTYPE html>
<html>
   <body ononline = "onlineFunc()" onoffline = "offlineFunc()">
      <script>
         function onlineFunc() {
            alert ("Working online!");
         }
         function offlineFunc() {
            alert ("Workinf offline!");
         }
      </script>
      <p>Got o the web browser menu bar and click the File menu. Select
      "Work Offline" and toggle between online and offline.</p>
   </body>
</html>

Updated on: 03-Mar-2020

70 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements