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 | |
| 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')
4 files changed, 230 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> diff --git a/files/zh-cn/web/api/storagemanager/index.html b/files/zh-cn/web/api/storagemanager/index.html new file mode 100644 index 0000000000..83676931c2 --- /dev/null +++ b/files/zh-cn/web/api/storagemanager/index.html @@ -0,0 +1,42 @@ +--- +title: StorageManager +slug: Web/API/StorageManager +translation_of: Web/API/StorageManager +--- +<p>{{securecontext_header}}{{SeeCompatTable}}{{APIRef("Storage")}}</p> + +<p><a href="https://developer.mozilla.org/zh-CN/docs/Web/API/Storage_API">Storage API</a>的<strong><code>StorageManager</code></strong>接口提供了用于管理数据本地存储权限和估算可用存储空间的接口。 您可以使用{{domxref("navigator.storage")}}或{{domxref("WorkerNavigator.storage")}}对此接口进行引用。</p> + +<h2 id="方法">方法</h2> + +<dl> + <dt>{{domxref("StorageManager.estimate()")}} {{securecontext_inline}}</dt> + <dd>返回一个{{domxref("StorageEstimate")}}对象,此对象包含为你的域名预留的存储空间总大小和你已经使用的存储空间大小。</dd> + <dt>{{domxref("StorageManager.persist()")}} {{securecontext_inline}}</dt> + <dd>如果您的user agent能够将你域名下的数据持久保存,那么将返回一个状态为resolve的{{jsxref('Promise')}}</dd> + <dt>{{domxref("StorageManager.persisted()")}} {{securecontext_inline}}</dt> + <dd>如果您的站点已经被授予可使用数据本地存储的权限,则返回一个状态为resolve的{{jsxref('Promise')}}</dd> +</dl> + +<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','#storagemanager','StorageManger')}}</td> + <td>{{Spec2('Storage')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.StorageManager")}}</p> diff --git a/files/zh-cn/web/api/storagemanager/persist/index.html b/files/zh-cn/web/api/storagemanager/persist/index.html new file mode 100644 index 0000000000..2f778b9832 --- /dev/null +++ b/files/zh-cn/web/api/storagemanager/persist/index.html @@ -0,0 +1,53 @@ +--- +title: StorageManager.persist() +slug: Web/API/StorageManager/persist +translation_of: Web/API/StorageManager/persist +--- +<p>{{securecontext_header}}{{APIRef("Storage")}}{{SeeCompatTable}}</p> + +<p><span class="seoSummary"><strong><code>persist()</code></strong></span>方法是<span class="seoSummary">{{domxref("StorageManager")}}的一个接口,用于请求本地数据存储的权限,如果被授予权限,则返回一个resolved状态值为<code>true</code>的{{jsxref('Promise')}}对象,否则返回<code>false</code>。</span></p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">navigator.storage.persist().then(function(persistent) { ... })</pre> + +<h3 id="参数">参数</h3> + +<p>无</p> + +<h3 id="返回值">返回值</h3> + +<p>一个resolved状态,值为{{jsxref('Boolean')}}类型的{{jsxref('Promise')}}对象。</p> + +<h2 id="示例">示例</h2> + +<pre class="brush: js">if (navigator.storage && navigator.storage.persist) + navigator.storage.persist().then(function(persistent) { + if (persistent) + console.log("Storage will not be cleared except by explicit user action"); + else + console.log("Storage may be cleared by the UA under storage pressure."); + });</pre> + +<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-persist','persist')}}</td> + <td>{{Spec2('Storage')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.StorageManager.persist")}}</p> diff --git a/files/zh-cn/web/api/storagemanager/persisted/index.html b/files/zh-cn/web/api/storagemanager/persisted/index.html new file mode 100644 index 0000000000..0e3c7c4711 --- /dev/null +++ b/files/zh-cn/web/api/storagemanager/persisted/index.html @@ -0,0 +1,53 @@ +--- +title: StorageManager.persisted() +slug: Web/API/StorageManager/persisted +translation_of: Web/API/StorageManager/persisted +--- +<p>{{securecontext_header}}{{APIRef("Storage")}}{{SeeCompatTable}}</p> + +<p><span class="seoSummary"><strong><code>persisted()</code></strong></span>方法是<span class="seoSummary">{{domxref("StorageManager")}}的一个接口,如果盒存储模式(</span><strong>box mode</strong><span class="seoSummary">)的值为 “<strong>persistent</strong>” 则返回一个resolved状态值为<code>true</code>的{{jsxref('Promise')}}。</span></p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">navigator.storage.persisted().then(function(persistent) { ... })</pre> + +<h3 id="参数">参数</h3> + +<p>无</p> + +<h3 id="返回值">返回值</h3> + +<p>一个状态为resolved,值为{{jsxref('Boolean')}}类型的{{jsxref('Promise')}}。</p> + +<h2 id="示例">示例</h2> + +<pre class="brush: js"><code>if (navigator.storage && navigator.storage.persist) + navigator.storage.persisted().then(function(persistent) { + if (persistent) + console.log("Storage will not be cleared except by explicit user action"); + else + console.log("Storage may be cleared by the UA under storage pressure."); + });</code></pre> + +<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-persisted','persisted')}}</td> + <td>{{Spec2('Storage')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.StorageManager.persisted")}}</p> |
