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

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


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