Im trying to get the battery level through battery api. It works fine in firefox. But in chrome (navigator.webkitBattery) is not working. Any help will be much appreciated. Thanks in advance.
var battery = navigator.battery || navigator.mozBattery || navigator.webkitBattery;
alert(battery.level)
well, on chrome ver 39.0+, there is navigator.getBattery method, which return a promise object when call. so the code could be like below:
var battery = navigator.battery || navigator.mozBattery;
if (battery) {
// battery status for firefox
alert(battery.level * 100 + '%');
} else if (navigator.getBattery) {
//battery status for chrome
navigator.getBattery().then(function(battery) {
alert(battery.level * 100 + '%');
});
}
The shortest answer is that it is not implemented, and is not going to be implemented for a little while.
Update: Jan 2015. This is now available in Chrome (see answer below)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With