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


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

示例

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

更新於:03-03-2020

183 次瀏覽

開啟您的職業生涯

透過完成課程獲得認證

立即開始
廣告
© . All rights reserved.