安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
estimate()
方法在
StorageManager
接口询问存储管理器有多少存储对于当前
origin
占用 (
usage
),和多少可用空间 (在该规范中的 NaN 定义。
quota
).
This method operates asynchronously, so it returns a
Promise
which resolves once the information is available. The promise's fulfillment handler is called with a
StorageEstimate
containing the usage and quota data.
const estimatePromise = StorageManager.estimate();
None.
Promise
that resolves to an object which conforms to the
StorageEstimate
dictionary. This dictionary contains estimates of how much space is available to the origin in
StorageEstimate.quota
, as well as how much is currently used in
StorageEstimate.usage
.
返回值不精确; between compression, deduplication, and obfuscation for security reasons, they will be imprecise.
You may find that the
quota
varies from origin to origin. This variance is based on factors such as:
In this example, we obtain the usage estimates and present the percentage of storage capacity currently used to the user.
<label> You’re currently using about <output id="percent"> </output>% of your available storage. </label>
navigator.storage.estimate().then(function(estimate) {
document.getElementById("percent").value =
(estimate.usage / estimate.quota * 100).toFixed(2);
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
存储
The definition of 'estimate()' in that specification. |
实时标准 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
estimate
|
Chrome 52 | Edge ≤79 | Firefox 51 | IE ? | Opera Yes | Safari ? | WebView Android 52 | Chrome Android 52 | Firefox Android 51 | Opera Android Yes | Safari iOS ? | Samsung Internet Android 6.0 |
完整支持
兼容性未知
存储
,对象的返回通过
Window.localStorage
StorageManager
navigator.storage
StorageManager
estimate()
persist()
persisted()