首页 > 其他 > 详细

ServiceWorker.state

时间:2017-09-10 18:30:42      阅读:243      评论:0      收藏:0      [点我收藏+]

ServiceWorker.state

ServiceWorker.state

  The state read-only property of the ServiceWorker interface returns a string representing the current state of the service worker. It can be one of the following values: installinginstalled, activatingactivated, or redundant.

 

ServiceWorkerRegistration.installing

  The installing property of the ServiceWorkerRegistration interface returns a service worker whoseServiceWorker.state is installing. This property is initially set to null.

ServiceWorkerRegistration.waiting

  The waiting property of the ServiceWorkerRegistration interface returns a service worker whoseServiceWorker.state is installed. This property is initially set to null.

ServiceWorkerRegistration.active

  The active property of the ServiceWorkerRegistration interface returns a service worker whoseServiceWorker.state is activating or activated. This property is initially set to null.

 

技术分享
var serviceWorker;
if (registration.installing) {
  serviceWorker = registration.installing;
  document.querySelector(‘#kind‘).textContent = ‘installing‘;
} else if (registration.waiting) {
  serviceWorker = registration.waiting;
  document.querySelector(‘#kind‘).textContent = ‘waiting‘;
} else if (registration.active) {
  serviceWorker = registration.active;
  document.querySelector(‘#kind‘).textContent = ‘active‘;
}

if (serviceWorker) {
  logState(serviceWorker.state);
  serviceWorker.addEventListener(‘statechange‘, function(e) {
  logState(e.target.state);
  });
}
View Code

 

ServiceWorkerContainer.controller

  The controller read-only property of the ServiceWorkerContainer interface returns a ServiceWorker object if its state is activated (the same object returned by ServiceWorkerRegistration.active). This property returns null if the request is a force refresh (Shift + refresh) or if there is no active worker.

参考:

1、https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/state

2、https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/waiting

ServiceWorker.state

原文:http://www.cnblogs.com/tekkaman/p/7501564.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!