安全上下文
此特征只可用于 安全上下文 (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:

  • How often the user visits
  • Public site popularity data
  • User engagement signals like bookmarking, adding to homescreen, or accepting push notifications

范例

In this example, we obtain the usage estimates and present the percentage of storage capacity currently used to the user.

HTML 内容

<label>
  You’re currently using about <output id="percent">
  </output>% of your available storage.
</label>
					

JavaScript 内容

navigator.storage.estimate().then(function(estimate) {
  document.getElementById("percent").value =
      (estimate.usage / estimate.quota * 100).toFixed(2);
});
					

结果

规范

规范 状态 注释
存储
The definition of 'estimate()' in that specification.
实时标准 初始定义。

浏览器兼容性

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
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

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: