求助~~~~~判断手机是否连接上 navigator.connection.type;

我使用navigator.connection.type的时候发现怎么样都无法运行
网上下载了这个cordova.js,运行就死循环,卡死浏览器。不加这个,又无法使用。。。

 <!DOCTYPE html> 

    <html> 

    <head> 

    <title>navigator.network.connection.type Example</title>  

     
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager"/> 
     <script src="js/jquery-1.11.3.js"></script>
     <script type="text/javascript" charset="utf-8" src="js/cordova.js"></script> 
    <script type="text/javascript" charset="utf-8">   

    
        // 等待加载PhoneGap 

        document.addEventListener("deviceready", onDeviceReady, false);   

     

        // PhoneGap加载完毕,可以安全调用PhoneGap方法 

        function onDeviceReady() {  

            checkConnection();  
            console.log(navigator.network)
        }   

     

        function checkConnection() {  

            var networkState = navigator.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';  

     

            alert('Connection type: ' + states[networkState]);  

    } 

     

    </script> 

    </head> 

    <body> 

        <p>A dialog box will report the network state.</p> 

    </body> 

    </html> 
查看回复