Phonegap拦截菜单按键的事件menubutton,用于处理html5当中的菜单拦截事件
此事件是当用户按下菜单是时候触发
document.addEventListener("menubutton", yourCallbackFunction, false);
支持平台:
简单例子:
document.addEventListener("menubutton", onMenuKeyDown, false); function onMenuKeyDown() { // Handle the back button }
完整例子:
<html> <head> <title>Menu Button Example</title> <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() { //菜单按钮的执行 } </script> </head> <body onload="onLoad()"> </body> </html>
deviceready只需要加载一次即可 它表示当phonegap的API加载完毕的时候调用