cordova-2.0.0.js没有使用phonegap在android上工作

时间:2012-09-12 13:10:28

标签: javascript android html5 windows-phone-7 cordova

我是一名新的PhoneGap程序员。 navigator.notification.alert()没有使用phonegap在Android上工作。但它适用于iPhone和WP7。我正在Windows Phone 7中开发此应用程序。

感谢您的帮助

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>Cordova WP7</title>
    <link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title"
        charset="utf-8" />
    <!--<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>-->  
    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <script type="text/javascript">
        function doAlert() {
            var message = "This is an Alert dialog";
            var title = "Attention!";
            navigator.notification.alert(message, title);
        };       

    </script>
</head>
<body>
    <h1>
        Cordova Tests</h1>
    <div id="info">
         <a href="#" onclick="doAlert()">Click Me</a>  
    </div>
</body>
</html>


最后,我得到了解决方案。

解决方案:

      在我们构建手机密码之前(在 build.phonegap.com 中),我们需要删除 cordova-2.0.0.js 文件。如果我们删除此 cordova-2.0.0.js ,那么phonegap代码正在处理andriod。

1 个答案:

答案 0 :(得分:2)

您必须等待DeviceReady

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale = 1.0, maximum-scale=1.0, user-scalable=no" />
<script type="text/javascript" charset="utf-8" src="windows/cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
    var deviceReady = false;
    function init() {
        document.addEventListener("deviceready", function () {
            deviceReady = true;
        }, false);

        window.setTimeout(function () {
            if (!deviceReady) {
                alert("Error: Phonegap did not initialize.  Demo will not run correctly.");
                console.log("Error: Phonegap did not initialize.  Demo will not run correctly.");
            }
        }, 1000);
    }

    function doAlert() {
        var message = "This is an Alert dialog";
        var title = "Attention!";
        navigator.notification.alert(message, title);
    }
</script>
</head>
<body onLoad="init();">
<h1>Cordova Tests</h1>
<div id="info">
    <button onclick="doAlert();">Click Me</button>
</div>
</body>
</html>