From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/storagemanager/estimate/index.html | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 files/zh-cn/web/api/storagemanager/estimate/index.html (limited to 'files/zh-cn/web/api/storagemanager/estimate') diff --git a/files/zh-cn/web/api/storagemanager/estimate/index.html b/files/zh-cn/web/api/storagemanager/estimate/index.html new file mode 100644 index 0000000000..6f094fa705 --- /dev/null +++ b/files/zh-cn/web/api/storagemanager/estimate/index.html @@ -0,0 +1,82 @@ +--- +title: StorageManager.estimate() +slug: Web/API/StorageManager/estimate +translation_of: Web/API/StorageManager/estimate +--- +

{{securecontext_header}}{{APIRef("Storage")}}

+ +

estimate()方法是{{domxref("StorageManager")}}的一个接口,用于估算某一个域名(或一个站点)下Storage Manager的总存储空间和已经使用了的存储空间。此方法为一个异步方法,如果此方法可用,那么其返回一个结果为resolved的{{jsxref("Promise")}}对象。resolved接收的参数是一个带有已使用数据存储空间和总可用总存储空间的{{domxref("StorageEstimate")}}对象。

+ +

语法

+ +
var estimatePromise = StorageManager.estimate();
+ +

参数

+ +

+ +

返回值

+ +

{{domxref('StorageEstimate')}}类型的状态为resolved的{{jsxref('Promise')}}

+ +

此数据包含了此应用(或域名)可用的存储空间({{domxref("StorageEstimate.quota")}})和目前已经使用了的存储空间({{domxref("StorageEstimate.usage")}})。

+ +

这些值不是明确的数字,在进行压缩,重复数据删除和出于安全原因起见进行了混淆之后,这个数据是不精确的。

+ +

你可能会发现不同的应用或站点分配的存储空间不同,具体取决于用户访问频率,和网站受欢迎程度等数据。

+ +

示例

+ +

在这个示例中,我们使用estimate()得到目前所使用的存储空间占全部存储空间的百分比。

+ +

HTML 内容

+ +
<p>
+  You're currently using about <span id="percent">
+  </span>% of your available storage.
+</p>
+
+ +

JavaScript 内容

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

结果

+ +

{{ EmbedLiveSample('Example', 600, 40) }}

+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Storage','#dom-storagemanager-estimate','estimate()')}}{{Spec2('Storage')}}Initial definition.
+ +

浏览器兼容性

+ + + +

{{Compat("api.StorageManager.estimate")}}

+ +

参见

+ + -- cgit v1.2.3-54-g00ecf