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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With