levelchange Redirect 2

The levelchange event is fired when the level attribute of the battery API has changed.

General info

Specification
Battery
Interface
Event
Bubbles
No
Cancelable
No
Target
navigator.battery
Default Action
None

Properties

The event callback doesn't receive any event objects, but properties can be read from the navigator.battery interface.

Property Type Description
charging boolean The system's battery charging status. Returns true if the battery is charging, if the state of the system's battery is not determinable, or if no battery is attached to the system. Returns false if the battery is discharging. Read only.
chargingTime double (float) The remaining time in seconds until the system's battery is fully charged. Returns 0 if the battery is fully charged. Returns positive infinity, if the battery is discharging or if the implementation is unable to report the remaining charging time. Read only.
dischargingTime double (float) the remaining time in seconds until the system's battery is completely discharged and the system is about to be suspended. Returns positive infinity if the battery is charging, if the implementation is unable to report the remaining discharging time, or if there is no battery attached to the system. Read only.
level double (float) The system's battery charging level scaled from 0 to 1.0. Returns 0 if the battery is empty and the system is about to suspend. Returns 1.0 if the battery is full, if the implementation is unable to report the battery's level, or if there is no battery attached to the system. Read only.

Example

 
var battery = navigator.battery || navigator.mozBattery || navigator.webkitBattery; 
 
function updateBatteryStatus() { 
  alert("Battery status: " + battery.level * 100 + " %"); 
 
  if (battery.charging) { 
    alert("Battery is charging");  
  } 
} 
 
battery.addEventListener("chargingchange", updateBatteryStatus); 
battery.addEventListener("levelchange", updateBatteryStatus); 
updateBatteryStatus(); 

Document Tags and Contributors

Contributors to this page: Sheppy
Last updated by: Sheppy,