PhoneGap的错误 - "未捕获的Ref​​erenceError:科尔多瓦没有定义" [英] PhoneGap error - "Uncaught ReferenceError: cordova is not defined"

查看:180
本文介绍了PhoneGap的错误 - "未捕获的Ref​​erenceError:科尔多瓦没有定义"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用在Android菜单键,与PhoneGap的。问题是,我不能使用它,因为出现在日志此错误:

I'm trying use the menu button on Android, with the PhoneGap. The problem is that I can't use it because appear this error on log:

未捕获的Ref​​erenceError:科尔多瓦没有定义。

"Uncaught ReferenceError: cordova is not defined".

这是源:

<!DOCTYPE html>
<html>
    <head>
            <!--<script type="text/javascript" charset="utf-8" src="js/cordova-2.6.0.js"></script>-->
            <!--<script type="text/javascript" charset="utf-8" src="cordova-2.6.0.js"></script>-->
            <!--<script type="text/javascript" charset="utf-8" src="js/cordova.js"></script>-->
            <script type="text/javascript" charset="utf-8" src="cordova.js"></script>

            <script type="text/javascript">
                function onLoad() {
                    document.addEventListener("deviceready", function () {
                        document.addEventListener("menubutton", function(){
                            alert('Menu button pressed.');    
                        }, true);
                    }, false);
                }
            </script>

    </head>
    <body onload="onLoad()">
            <p>Hello world!</p>
        </body>
</html>

我认为这个问题是cordova.js的进口,所以我尝试使用了评论,这一切的选择。

I thought that the problem was the import of cordova.js, so I tried use all this options that were commented.

我不知道是否有任何关系,但所有的时候,我开始了剧本,出现这个错误在控制台,用红色:

I don't know if have any relation, but all the times I start the script, appear this error in the console, with the red color:

E/webview(21743): registerForStylusPenEvent onAttachedToWindow
E/webview(21743): registerForStylusPenEvent START
E/webview(21743): registerForStylusPenEvent END

我很抱歉,如果有一些英文的错误,但我想这样做,而不谷歌翻译。

I'm sorry if had some english error, but I'm trying do it without the Google Translator.

感谢你。

推荐答案

首先请检查路径和文件名到您的cordova.js是correc。然后取出onLoad事件,并写在脚本文件的deviceready事件挂钩,如下所示:

First pls check that the path and file name to your cordova.js is correc. Then remove the onLoad event and write the deviceready event hook in the script file as shown below:

<!DOCTYPE html>
<html>
    <head>
            <!--<script type="text/javascript" charset="utf-8" src="js/cordova-2.6.0.js"></script>-->
            <!--<script type="text/javascript" charset="utf-8" src="cordova-2.6.0.js"></script>-->
            <!--<script type="text/javascript" charset="utf-8" src="js/cordova.js"></script>-->
            <script type="text/javascript" charset="utf-8" src="cordova.js"></script>

            <script type="text/javascript">

                    document.addEventListener("deviceready", function () {
                        document.addEventListener("menubutton", function(){
                            alert('Menu button pressed.');    
                        }, true);
                    }, false);

            </script>

    </head>
    <body ">
            <p>Hello world!</p>
        </body>
</html>

这篇关于PhoneGap的错误 - &QUOT;未捕获的Ref​​erenceError:科尔多瓦没有定义&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆