Home Science Technology Know the Battery Status of your Visitor’s Mobile Phone

When someone visits your website, you can easily retrieve information about the charge level of their mobile or laptop's battery through the Battery Status API (live demo). This is currently supported on Google Chrome, Opera & Firefox on the desktop and Chrome for Android.

The Battery API can be implemented with few lines of JavaScript code and reveals all the required details about the device's battery charge level. You'll get to know:

  1. Whether or not the visitor's battery is currently being charged.
  2. How much is the battery charged?
  3. If charging, how many seconds until the battery is fully charged.
  4. The remaining time in seconds until the battery is completely discharged.
  5. Battery Status Demo

    You can attach event listeners so the battery data is updated as soon as the charge level of the hardware's battery is changed while the visitor is still on your page. You can go one step further and even integrate this with Google Analytics and store the battery charge level of your visitor's devices using Events in Analytics.

    <script>

    if (navigator.getBattery) {
    navigator.getBattery().then(function(battery) {
    display(battery);
    });
    } else if (navigator.battery) {
    display(navigator.battery);
    } else ...read more

Share your comments