2014-03-27 87 views
1
!DOCTYPE html> 
<html> 
    <head> 
    <title>navigator.connection.type Example</title> 

    <script type="text/javascript" charset="utf-8" src="js/libs/cordova-2.0.0.js"></script> 
    <script> 

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

    function onDeviceReady() { 
     checkConnection(); 
    } 

    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> 
    <a href="#" onclick="checkConnection();">Just</a> 
    </body> 
</html> 

我想在Android手機 獲得Internet連接類型這是我從 它給了我錯誤的ReferenceError官方的PhoneGap頁簡稱代碼:找不到變量:在文件連接PhoneGap的參考未找到錯誤

請幫我把它弄出來......

+0

您正在使用phonegap構建來構建您的應用程序? – Suhas

回答

0

如果使用PhoneGap的生成,生成你必須包括在頭部分Phongap.js標籤應用程序泰德。 Like-

<script src="phonegap.js"></script> 

你只需要包含這個標籤,其餘的Phoneap會照顧到這一點。

有關網絡狀態,請參閱Phonegap Doc