The chargingchange
event is fired when the charging
attribute of the battery API has changed.
BatteryManager
The event callback doesn't receive any event objects, but properties can be read from the BatteryManager
object received from the navigator.getBattery
method.
Property | Type | Description |
---|---|---|
BatteryManager.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. |
navigator.getBattery().then(function(battery) { console.log("Battery charging? " + (battery.charging ? "Yes" : "No")); battery.addEventListener('chargingchange', function() { console.log("Battery charging? " + (battery.charging ? "Yes" : "No")); }); });
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/Events/chargingchange