ContentIndex: delete() 方法
注意:此功能在 Web Workers 中可用。
ContentIndex 接口的 delete() 方法用于取消索引中某个条目的注册。
注意: 调用 delete() 只会影响索引。它不会从 中删除任何内容。Cache
语法
js
delete(id)
参数
id-
您希望
对象移除的已索引内容的唯一标识符。ContentIndex
返回值
返回一个解析为 undefined 的 Promise。
异常
不会抛出任何异常。
示例
下面是一个异步函数,它从 内容索引 中移除一个条目。我们接收当前 的引用,这使我们能够访问 ServiceWorkerRegistration 属性,从而访问 indexdelete 方法。
js
async function unregisterContent(article) {
// reference registration
const registration = await navigator.serviceWorker.ready;
// feature detect Content Index
if (!registration.index) return;
// unregister content from index
await registration.index.delete(article.id);
}
delete 方法也可以在 Service Worker 作用域内使用。
js
self.registration.index.delete("my-id");
规范
| 规范 |
|---|
| Content Index # content-index-delete |
浏览器兼容性
加载中…