1

我刚刚开始phonegap,当我运行这段代码时

索引.html

<!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() { // Always this condtion met
                    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.");
                    }
                }, 3000);
            }

            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>

当我运行此代码时,我收到此错误

03-19 16:37:40.998:E/Web 控制台(854):TypeError:表达式“navigator.notification”[未定义] 的结果不是对象。在文件:///android_asset/www/index.html:25

在此先感谢朋友,希望您能理解。

4

1 回答 1

1

您确定在 index.html 文件中包含了正确的 Cordova.js 文件吗?您应该始终确保您的 Cordova 文件的名称应该与您在索引文件中的名称相匹配。

检查你的:

<script type="text/javascript" charset="utf-8" src="windows/cordova-2.0.0.js"></script>
于 2013-03-19T16:15:49.417 回答