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 事件属性如何运作的−
广告