【问题标题】:PhoneGap Reference Not found ErrorPhoneGap 参考未找到错误
【发布时间】:2014-05-05 23:16:51
【问题描述】:
!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 连接类型 这是我从官方PhoneGap页面引用的代码 它给了我错误 ReferenceError: Can't find variable: Connection at file

请帮助我摆脱它...

【问题讨论】:

  • 您正在使用 phonegap build 来构建您的应用程序?

标签: android cordova compiler-errors cordova-2.0.0


【解决方案1】:

如果您使用 PhoneGap Build 来构建您的应用程序,您必须在 head 部分包含 Phongap.js 标记。喜欢-

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

你只需要包含这个标签,剩下的 Phoneap 会处理的。

请参阅Phonegap Doc 了解网络状态。

【讨论】:

    猜你喜欢
    • 2015-11-20
    • 2012-10-08
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多