【问题标题】:In Phonegap i get error assest.html while executing this index.html file在 Phonegap 中,执行此 index.html 文件时出现错误 assest.html
【发布时间】:2026-02-14 21:15:02
【问题描述】:

我刚刚启动 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 控制台 (854): TypeError: 结果 表达式 'navigator.notification' [未定义] 不是对象。在 文件:///android_asset/www/index.html:25

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

【问题讨论】:

    标签: cordova phonegap-plugins phonegap-build


    【解决方案1】:

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

    检查你的:

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

    【讨论】:

    • 但是为什么是“windows/cordova-2.0.0.js”???您没有名为“windows”的子文件夹。它应该只是 src="cordova-2.0.0.js"。试试这个,看看问题是否仍然存在。