StorageManager.persist()

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

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

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

persist()方法是StorageManager的一个接口,用于请求本地数据存储的权限,如果被授予权限,则返回一个resolved状态值为truePromise对象,否则返回false

语法

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

参数

返回值

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

示例

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

规范

Specification Status Comment
Storage
persist
Living Standard Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
persistChrome Full support 52
Full support 52
No support 48 — 52
Alternate Name
Alternate Name Uses the non-standard name: requestPersistent
Edge Full support ≤79Firefox Full support 55IE No support NoOpera Full support YesSafari ? WebView Android Full support 52
Full support 52
No support 48 — 52
Alternate Name
Alternate Name Uses the non-standard name: requestPersistent
Chrome Android Full support 52
Full support 52
No support 48 — 52
Alternate Name
Alternate Name Uses the non-standard name: requestPersistent
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: requestPersistent

Legend

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