Detect the Internet connection is offline?

后端 未结 19 1403
甜味超标
甜味超标 2020-11-22 00:53

How to detect the Internet connection is offline in JavaScript?

19条回答
  •  长发绾君心
    2020-11-22 01:40

    I think it is a very simple way.

    var x = confirm("Are you sure you want to submit?");
    if (x) {
      if (navigator.onLine == true) {
        return true;
      }
      alert('Internet connection is lost');
      return false;
    }
    return false;
    

提交回复
热议问题