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 事件屬性如何運作的−

廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP