过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
Indicates the amount of time, in seconds, that remains until the battery is fully discharged.
Even if the time returned is precise to the second, browsers round them to a higher interval (typically to the closest 15 minutes) for privacy reasons.
var time = battery.dischargingTime
On return,
time
is the remaining time in seconds until the
battery
, which is a
BatteryManager
object, is fully discharged and the system will suspend. This value is
Infinity
if the battery is currently charging rather than discharging, or if the system is unable to report the remaining discharging time.
<div id="dischargingTime">(discharging time unknown)</div>
navigator.getBattery().then(function(battery) {
var time = battery.dischargingTime;
document.querySelector('#dischargingTime').textContent = battery.dischargingTime;
});
| 规范 | 状态 | 注释 |
|---|---|---|
| Battery Status API | 候选推荐 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
dischargingTime
弃用
|
Chrome 38 | Edge 79 |
Firefox
16 — 52
|
IE No | Opera 25 | Safari No | WebView Android 40 |
Chrome Android
38
|
Firefox Android
10 — 16
Prefixed
|
Opera Android 25 | Safari iOS ? — ? |
Samsung Internet Android
3.0
|
完整支持
不支持
弃用。不要用于新网站。
见实现注意事项。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
BatteryManager