onofflineEvent
Example
Execute JavaScript when the browser is offline:
<body onoffline="myFunction()">
Try it Yourself »
Definition and Usage
The onoffline event fires when the browser is offline.
Tip:The opposite event of the onoffline event isononline 。
Tip:You can also usenavigator.onLinethe property to detect whether the browser is in online or offline mode.
Browser Support
The numbers in the table indicate the first browser version that supports this event.
| Event | |||||
|---|---|---|---|---|---|
| onoffline | Not supported |
IE11: Deprecated 8.0 |
3.0 | Not supported | Not supported |
Syntax
In HTML:
<element onoffline="myScript">Try it Yourself
In JavaScript:
object.onoffline=function(){myScript};Try it Yourself
In JavaScript, using the addEventListener() method:
object.addEventListener("offline", myScript);Try it Yourself
Note:Internet Explorer 8 and earlier IE versions do not supportaddEventListener()the method.
Technical Details
| Bubbles: | No |
|---|---|
| Cancelable: | No |
| Event type: | Event |
| Supported HTML tags: | <body> |
Event Object Other Extensions