StorageManager.persisted()

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

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

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

语法

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

参数

返回值

一个状态为 resolved,值为Boolean类型的Promise

示例

js
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
# dom-storagemanager-persisted

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
persisted

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support