Alert box when no internet connection - Phonegap

后端 未结 9 2663
南方客
南方客 2021-02-20 06:55

I\'m trying to get a pop-up to, well, pop up when there is no internet connection on the device.

I got the following example working, but now I want the alert only to sh

9条回答
  •  你的背包
    2021-02-20 07:32

    Try the below code.  
    
    var networkState = navigator.network.connection.type;
    var states = {};
    states[Connection.UNKNOWN]  = 'Unknown connection';
    states[Connection.ETHERNET] = 'Ethernet connection';
    states[Connection.WIFI]     = 'WiFi connection';
    states[Connection.CELL_2G]  = 'Cell 2G connection';
    states[Connection.CELL_3G]  = 'Cell 3G connection';
    states[Connection.CELL_4G]  = 'Cell 4G connection';
    states[Connection.NONE]     = 'No network connection';
    
    if ((states[networkState]) == states[Connection.NONE])
    {
    alert("Please check your internet connectivity and try again"); 
    }
    

提交回复
热议问题