Phonegap攔截菜單按鍵的事件menubutton,用於處理html5當中的菜單攔截事件
此事件是當用戶按下菜單是時候觸發
document.addEventListener("menubutton", yourCallbackFunction, false);
支持平台:
Amazon Fire OSAndroidBlackBerry 10
簡單例子:
document.addEventListener("menubutton", onMenuKeyDown, false); function onMenuKeyDown() { // Handle the back button }
完整例子:
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() { //菜單按鈕的執行 } </script>
deviceready只需要加載一次即可 它表示當phonegap的API加載完畢的時候調用