unregister()
方法在
ServiceWorkerRegistration
interface unregisters the service worker registration and returns a
Promise
. The promise will resolve to
false
if no registration was found, otherwise it resolves to
true
irrespective of whether unregistration happened or not (it may not unregister if someone else just called
ServiceWorkerContainer.register()
with the same scope.) The service worker will finish any ongoing operations before it is unregistered.
注意 : This feature is available in Web 工作者 .
serviceWorkerRegistration.unregister().then(function(boolean) {
});
None.
Promise
resolves with a boolean indicating whether the service worker has unregistered or not.
The following simple example registers a service worker example, but then immediately unregisters it again:
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw-test/sw.js', {scope: 'sw-test'}).then(function(registration) {
// registration worked
console.log('Registration succeeded.');
registration.unregister().then(function(boolean) {
// if boolean = true, unregister is successful
});
}).catch(function(error) {
// registration failed
console.log('Registration failed with ' + error);
});
};
| 规范 | 状态 | 注释 |
|---|---|---|
|
服务工作者
The definition of 'ServiceWorkerRegistration.unregister()' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
unregister
|
Chrome 40 |
Edge
17
|
Firefox
44
|
IE No | Opera 27 | Safari 11.1 | WebView Android 40 | Chrome Android 40 | Firefox Android 44 | Opera Android 27 | Safari iOS 11.3 | Samsung Internet Android 4.0 |
完整支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
用户必须明确启用此特征。
ServiceWorkerRegistration
getNotifications()
showNotification()
unregister()
update()