码迷,mamicode.com
首页 > 其他好文 > 详细

ServiceWorker.state

时间:2017-09-10 18:58:33      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:col   des   nta   contain   web   logs   sys   unique   represent   

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

标签:col   des   nta   contain   web   logs   sys   unique   represent   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!