StorageManager.persisted()

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

Experimental: 这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

**persisted()**方法是StorageManager的一个接口,如果盒存储模式(box mode)的值为“persistent”则返回一个 resolved 状态值为truePromise

语法

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

参数

返回值

一个状态为 resolved,值为Boolean类型的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
Storage Standard
# dom-storagemanager-persisted

浏览器兼容性

BCD tables only load in the browser