HTML onoffline 事件屬性


HTML onoffline 事件屬性會在瀏覽器開始離線工作時觸發。

語法

以下是語法 −

<tagname onoffline=”script”></tagname>

讓我們看一個 HTML onoffline 事件屬性的示例−

示例

 線上演示

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

輸出

現在嘗試啟用/停用你的網路,觀察 onoffline/ononline 事件屬性如何運作的−

更新於: 27-Sep-2019

68 次瀏覽

開啟你的 職業

完成課程進行認證

開始
廣告
© . All rights reserved.