运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>HTML DOM Events</h1> <h2>The onoffline Event</h2> <p>Use the addEventListener() method to attach a "online" and "offline" event to the window object.</p> <p><b>NOTE:</b> There will only be an "output" from this example when the browser shifts from online to offline.</p> <p id="demo"></p> <script> window.addEventListener("online", onFunction); window.addEventListener("offline", offFunction); function onFunction() { document.getElementById("demo").innerHTML = "Your browser is working online."; } function offFunction() { document.getElementById("demo").innerHTML = "Your browser is working offline."; } </script> </body> </html>