瀏覽器開始離線工作時在 HTML 中執行指令碼?


當 Web 瀏覽器開始離線工作時,觸發onoffline 屬性。你可以嘗試執行以下程式碼來實現onoffline 屬性 −

示例

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

更新於: 2020 年 3 月 3 日

183 次瀏覽

開啟您的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.