April 2013
Intermediate to advanced
264 pages
7h 44m
English
One of the key concerns with portable devices is knowing their battery status. Mobile devices can get as little as seven or eight hours out of a full charge, whereas a laptop is lucky to get more than three or four hours. Knowing the status of the device’s battery can be important before you begin power-hungry processes or commence to download large files.
You can get information about the battery with the Battery Status API, which brings a set of attributes on the navigator.battery object. For example, to find out if the battery is currently charging, you can use the charging attribute to get a true or false value:
var batteryStatus = navigator.battery.charging;
To find the current battery level, you can use the level attribute, ...
Read now
Unlock full access