PhoneGap错误 - “未捕获ReferenceError:cordova未定义” [英] PhoneGap error - "Uncaught ReferenceError: cordova is not defined"

查看:263
本文介绍了PhoneGap错误 - “未捕获ReferenceError:cordova未定义”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Android上的菜单按钮,使用PhoneGap。问题是,我不能使用它,因为出现这个错误日志:



未捕获ReferenceError:cordova未定义。



这是源代码:

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

< script type =text / javascript>
function onLoad(){
document.addEventListener(deviceready,function(){
document.addEventListener(menubutton,function(){
alert按下。');
},true);
},false);
}
< / script>

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

我认为问题是导入cordova.js,所以我试图使用所有这些选项



我不知道是否有任何关系,但是所有的时候,我启动脚本,在控制台中出现这个错误,用红色: / p>

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



对不起,如果有一些英语错误,

解决方案

p>首先请检查您的cordova.js的路径和文件名是否正确。然后删除onLoad事件,并在脚本文件中写入 deviceready 事件钩子,如下所示:

 <!DOCTYPE html> 
< html>
< head>
<! - < script type =text / javascriptcharset =utf-8src =js / cordova-2.6.0.js>< / script>
<! - < script type =text / javascriptcharset =utf-8src =cordova-2.6.0.js>< / script>
<! - < script type =text / javascriptcharset =utf-8src =js / cordova.js>< / script>
< script type =text / javascriptcharset =utf-8src =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>


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:

"Uncaught ReferenceError: cordova is not defined".

This is the source:

<!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>

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.

Thank you.

解决方案

First please check that the path and file name to your cordova.js are correct. 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错误 - “未捕获ReferenceError:cordova未定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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