在Phonegap中,我在执行此index.html文件时收到错误assest.html

时间:2013-03-19 12:04:02

标签: cordova phonegap-plugins phonegap-build

我刚开始使用phonegap,当我运行此代码时

的index.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 Console(854):TypeError:结果   表达式'navigator.notification'[undefined]不是对象。在   文件:///android_asset/www/index.html:25

先谢谢你们,我希望你能被理解。

1 个答案:

答案 0 :(得分:1)

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

检查你的:

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