แอตทริบิวต์เหตุการณ์ HTML ออฟไลน์ถูกทริกเกอร์เมื่อเบราว์เซอร์เริ่มทำงานออฟไลน์
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
<tagname onoffline=”script”></tagname>
ให้เรามาดูตัวอย่างของ HTML onoffline event Attribute−
ตัวอย่าง
<!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> ผลลัพธ์

ตอนนี้ลองเปิด/ปิดเครือข่ายของคุณเพื่อดูว่าแอตทริบิวต์เหตุการณ์ออนไลน์/ออนไลน์ทำงานอย่างไร -
