Working with the JavaScript Battery API

0
267
views
Working with the JavaScript Battery API

In this tutorial, we’re going to show you how to use the JavaScript Battery API to improve the user experience for people in desperate need of a charger. We’ll look at the Battery API itself, as well as some techniques for getting the most out of every drop of the most precious of resources!

Some browsers lack support for the Battery API (you guessed it; Safari and IE), so a quick support check can go a long way in terms of debugging:

if(navigator.getBattery){
// Battery API available.
// Rest of code goes here.
}
else{
// No battery API support.
// Handle error accordingly.
}

Read Full Article

LEAVE A REPLY

Please enter your comment!
Please enter your name here