Reputation: 25
How to get the user's battery percentage on a web application using JavaScript.
Since it's a web application, it'll run on a browser. The percentage will be displayed on the webpage.
Upvotes: 0
Views: 5109
Reputation: 3886
You can use the Battery status API. It only works on some browsers like chrome.
navigator.getBattery()
.then(function(battery) {
console.log(battery.level);
});
You can find more information here.
The link provided is a candidate recommendation and is not a finalized api.
Upvotes: 9