zl程序教程

您现在的位置是:首页 >  后端

当前栏目

[PWA] Check Online Status by using the NavigatorOnLine API

API The by Using status check Online pwa
2023-09-14 09:00:50 时间

Even if you have your application fully cached, you couldn’t perform any external request without internet connection. That’s why in order to build an offline-capable application, you must know when it’s actually offline.

This lesson shows you how to use the NavigatorOnLine API and online/offline events in order to disable the functionality to send messages of the application.

 

    this.online = navigator.onLine
    window.addEventListener('online', () => (this.online = true))
    window.addEventListener('offline', () => {
      this.online = false
    })