The share of mobile devices is growing significantly in network traffic, and the network traffic it contributes so much that for mobile devices, we have created some APIs and design concepts separately. A very typical example is the W3C Battery State API, which allows an application to learn about the battery status information of a device. This article explores this new API and shows you how to integrate it into your existing applications.
Check whether the device supports itAt present, the battery API still has not received mainstream support. Therefore, before using this API, you need to confirm whether the current device supports this API. The function shown below returns a Boone value (True/False), indicating whether the current browser supports the battery status API.
This function first detects whether the navigator.battery object exists. If it does not exist, continue to detect Mozilla-specific
Does navigator.mozBattery exist? I've seen some code that also detects webkitBattery objects, but I can't confirm whether it exists in Chrome.
Reference documentation: https://developer.mozilla.org/en-US/docs/DOM/window.navigator.battery
XML/HTML Code Copy content to clipboard