The Phonegap intercepts the menu button event menubutton, which is used to process the menu interception event in html5.
This event is triggered when the user presses the menu
document.addEventListener("menubutton", yourCallbackFunction, false);
Supported platforms:
Amazon Fire OSAndroidBlackBerry 10
Simple Example:
document.addEventListener("menubutton", onMenuKeyDown, false);function onMenuKeyDown() { // Handle the back button}
Complete example:
Menu Button Example<Script type = "text/javascript" charset = "UTF-8" src = "cordova. js "> </script> <script type =" text/javascript "charset =" UTF-8 "> // Wait for device API libraries to load // function onLoad () {document. addEventListener ("deviceready", onDeviceReady, false);} // device APIs are available // function onDeviceReady () {// Register the event listener document. addEventListener ("menubutton", onMenuKeyDown, false);} // Handle the menu button // function onMenuKeyDown () {// execution of the menu button} </script>
Deviceready only needs to be loaded once. It indicates that it is called when the phonegap API is loaded.