- Overview
- The Command-line Interface
- Platform Guides
- Configuration Reference
- Embedding WebViews
- Plugin Development Guide
- Privacy Guide
- Domain Whitelist Guide
- Accelerometer
- Camera
- Capture
- Compass
- Connection
- Contacts
- Device
- Events
- File
- Geolocation
- Globalization
- InAppBrowser
- Media
- Notification
- Splashscreen
- Storage
online
This event fires when an application goes online, and the device becomes connected to the Internet.
document.addEventListener("online", yourCallbackFunction, false);
Details
The online
event fires when a previously unconnected device receives
a network connection to allow an application access to the Internet.
It relies on the same information as the Connection API, and fires
when the value of [connection.type](../connection/connection.type.html)
becomes NONE
.
Applications typically should use document.addEventListener
to
attach an event listener once the [deviceready](events.deviceready.html)
event fires.
Supported Platforms
- Android
- BlackBerry WebWorks (OS 5.0 and higher)
- iOS
- Windows Phone 7 and 8
- Tizen
- Windows 8
Quick Example
document.addEventListener("online", onOnline, false);
function onOnline() {
// Handle the online event
}
Full Example
<!DOCTYPE html>
<html>
<head>
<title>Online Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("online", onOnline, false);
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
}
// Handle the online event
//
function onOnline() {
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>
iOS Quirks
During initial startup, the first online
event (if applicable) takes
at least a second to fire, prior to which [connection.type](../connection/connection.type.html)
is
UNKNOWN
.
Windows Phone 7 Quirks
When running in the Emulator, the connection.status
is always unknown, so this event will not fire.
Windows Phone 8 Quirks
The Emulator reports the connection.type as Cellular
, which does not change, so events will not fire.