PhoneGap Error - "Unprepared ReferenceError: cordova not defined"

I am trying to use the menu button on Android using PhoneGap. The problem is that I cannot use it because this error occurs in the log:

"Unprepared ReferenceError: cordova undefined."

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 the problem was with importing cordova.js, so I tried using all of these parameters that were commented out.

I don’t know if there is any relation, but all the time when I run the script this error appears in the console with red color:

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

Sorry if you had an English error, but I'm trying to do this without Google Translator.

Thanks.

+7
source share
1 answer

First, check the path and file name on your cordova.js. Then remove the deviceready event and write the deviceready event 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> 
+7
source

All Articles