--- title: StorageManager.persisted() slug: Web/API/StorageManager/persisted translation_of: Web/API/StorageManager/persisted ---

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

persisted()方法是{{domxref("StorageManager")}}的一个接口,如果盒存储模式(box mode)的值为 “persistent” 则返回一个resolved状态值为true的{{jsxref('Promise')}}。

语法

navigator.storage.persisted().then(function(persistent) { ... })

参数

返回值

一个状态为resolved,值为{{jsxref('Boolean')}}类型的{{jsxref('Promise')}}。

示例

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.");
  });

规范

Specification Status Comment
{{SpecName('Storage','#dom-storagemanager-persisted','persisted')}} {{Spec2('Storage')}} Initial definition.

浏览器兼容性

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