diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/storagemanager/estimate | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/storagemanager/estimate')
-rw-r--r-- | files/zh-cn/web/api/storagemanager/estimate/index.html | 82 |
1 files changed, 82 insertions, 0 deletions
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 +--- +<p>{{securecontext_header}}{{APIRef("Storage")}}</p> + +<p><strong><code>estimate()</code></strong>方法是{{domxref("StorageManager")}}的一个接口,用于估算某一个域名(或一个站点)下Storage Manager的总存储空间和已经使用了的存储空间。此方法为一个异步方法,如果此方法可用,那么其返回一个结果为resolved的{{jsxref("Promise")}}对象。resolved接收的参数是一个带有已使用数据存储空间和总可用总存储空间的{{domxref("StorageEstimate")}}对象。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var <em>estimatePromise</em> = <em>StorageManager</em>.estimate();</pre> + +<h3 id="参数">参数</h3> + +<p>无</p> + +<h3 id="返回值">返回值</h3> + +<p>{{domxref('StorageEstimate')}}类型的状态为resolved的{{jsxref('Promise')}}</p> + +<p>此数据包含了此应用(或域名)可用的存储空间({{domxref("StorageEstimate.quota")}})和目前已经使用了的存储空间({{domxref("StorageEstimate.usage")}})。</p> + +<p>这些值不是明确的数字,在进行压缩,重复数据删除和出于安全原因起见进行了混淆之后,这个数据是不精确的。</p> + +<p>你可能会发现不同的应用或站点分配的存储空间不同,具体取决于用户访问频率,和网站受欢迎程度等数据。</p> + +<h2 id="Example" name="Example">示例</h2> + +<p>在这个示例中,我们使用estimate()得到目前所使用的存储空间占全部存储空间的百分比。</p> + +<h3 id="HTML_内容">HTML 内容</h3> + +<pre class="brush: html"><p> + You're currently using about <span id="percent"> + </span>% of your available storage. +</p> +</pre> + +<h3 id="JavaScript_内容">JavaScript 内容</h3> + +<pre class="brush: js">navigator.storage.estimate().then(function(estimate) { + document.getElementById("percent").innerHTML = + (estimate.usage / estimate.quota * 100).toFixed(2); +}); +</pre> + +<h3 id="结果">结果</h3> + +<p>{{ EmbedLiveSample('Example', 600, 40) }}</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Storage','#dom-storagemanager-estimate','estimate()')}}</td> + <td>{{Spec2('Storage')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.StorageManager.estimate")}}</p> + +<h2 id="参见">参见</h2> + +<ul> + <li>Storage API</li> + <li>{{domxref("Storage")}}, the object returned by {{domxref("Window.localStorage")}}</li> + <li>{{domxref("StorageManager")}}</li> + <li>{{domxref("navigator.storage")}}</li> +</ul> |