onoffline incident
onoffline Event
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body ononline="onFunction()" onoffline="offFunction()"> <p>打开文件菜单点击 "离线工作(Work Offline)" 来切换在线与离线模式。</p> <p><strong>注意:</strong> ononline 和 onoffline 事件只有 Firefox 和 Internet Explorer 8 到 10 版本的浏览器支持。</p> <script> function onFunction() { alert ("你的浏览器在线工作。"); } function offFunction() { alert ("你的浏览器离线工作。"); } </script> </body> </html>
Run Instance»
Click "Run instance" button to view the online instance
Definition and usage
onoffline event is triggered when the browser is working offline.
Tips: The opposite event of the onoffline event is ononline.
Tip: You can also use the navigator.onLine property to determine whether the browser is in online or offline mode.
Browser support
The number in the table indicates the version number of the first browser that supports the event.
Syntax
HTML:
<element onoffline="myScript ">Try it
In JavaScript:
object.onoffline=function(){myScript };Try it
In JavaScript, use the addEventListener() method:
object.addEventListener("offline", myScript);Try it
Note: Internet Explorer 8 and earlier IE versions do not support the addEventListener() method.
Technical details
Whether bubbling is supported: | No |
---|---|
Can be canceled: | No |
Event type: | Event |
<body> |