A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/en-US/docs/Web/API/BatteryManager/level below:

BatteryManager: level property - Web APIs

BatteryManager: level property

Limited availability

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The level read-only property of the BatteryManager interface indicates the current battery charge level as a value between 0.0 and 1.0. A value of 0.0 means the battery is empty and the system is about to be suspended. A value of 1.0 means the battery is full or the user agent is unable to report the battery status information. When its value changes, the levelchange event is fired.

Value

A number.

Examples Getting the battery level HTML
<button id="get-level">Get battery level</button>
<div id="output"></div>
JavaScript
const getLevel = document.querySelector("#get-level");
const output = document.querySelector("#output");

getLevel.addEventListener("click", async () => {
  if (!navigator.getBattery) {
    output.textContent = "Battery manager is unsupported";
  } else {
    const manager = await navigator.getBattery();
    const level = manager.level;
    output.textContent = `Battery level: ${level}`;
  }
});
Result Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4