StorageManager.persisted()

翻译不完整。 请帮助我们翻译这篇文章!

Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

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

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 Status Comment
Storage
persisted
Living Standard Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
persistedChrome Full support 52
Full support 52
No support 48 — 52
Alternate Name
Alternate Name Uses the non-standard name: persistentPermission
Edge Full support ≤79Firefox Full support 55IE ? Opera Full support YesSafari ? WebView Android Full support 52
Full support 52
No support 48 — 52
Alternate Name
Alternate Name Uses the non-standard name: persistentPermission
Chrome Android Full support 52
Full support 52
No support 48 — 52
Alternate Name
Alternate Name Uses the non-standard name: persistentPermission
Firefox Android Full support 55Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support 6.0
Full support 6.0
No support 5.0 — 6.0
Alternate Name
Alternate Name Uses the non-standard name: persistentPermission

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
Uses a non-standard name.
Uses a non-standard name.