弃用
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the 兼容性表格 at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

battery 只读特性返回 BatteryManager which provides information about the system's battery charge level and whether the device is charging and exposes events that fire when these parameters change. This interface was introduced in early drafts of the Battery Status API and but has been replaced with Promise -based Navigator.getBattery() .

battery property has been removed in favor of the standard Navigator.getBattery() method, which returns a battery Promise .

句法

var battery = navigator.battery;
					

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
battery 弃用 Chrome 20 — 29 Prefixed
不支持 20 — 29 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge No Firefox 16 — 50
不支持 16 — 50
Removed in favor of navigator.getBattery() .
The Battery API was supported on Android, Windows, and Linux with UPower installed. Support for macOS was available starting with Firefox 18.
不支持 11 — 16 Prefixed
Prefixed Implemented with the vendor prefix: moz
不支持 10 — 16 Disabled
Disabled ). To change preferences in Firefox, visit
IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android 16 — 50
不支持 16 — 50
Removed in favor of navigator.getBattery() .
The Battery API was supported on Android, Windows, and Linux with UPower installed. Support for macOS was available starting with Firefox 18.
不支持 14 — 16 Prefixed
Prefixed Implemented with the vendor prefix: moz
不支持 10 — 16 Disabled
Disabled ). To change preferences in Firefox, visit
Opera Android No Safari iOS No Samsung Internet Android No

图例

不支持

不支持

弃用。不要用于新网站。

弃用。不要用于新网站。

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改: