navigator.onLine not working cordova 5.0.0

后端 未结 2 605
感情败类
感情败类 2021-01-15 02:12

I am having problems with checking if a device has no internet connection. I am using cordova 5.0.0 CLI. This is my code:

if(navigator.onLine) {
  alert(\"on         


        
2条回答
  •  爱一瞬间的悲伤
    2021-01-15 02:55

    Add this to your index.html :

    document.addEventListener("offline", function(){ navigator.notification.alert("No connection found") }, false);
    

    It will alert you if there isn't a network connection.

    If you don't have the notification plugin :

    document.addEventListener("offline", function(){ alert("No connection found") }, false);
    

提交回复
热议问题