I am playing with my first PhoneGap/Android app, and am having trouble triggering $.mobile.changePage() from a PhoneGap/Cordova Event.
I’ve updated the code, whereas before it would trigger once. Now it does not trigger at all, but is closer to how it probably should be done.
Here is my code:
$(document).on('pageinit', function() {
document.addEventListener("searchbutton", onSearchKeyDown, false); //never fires
document.addEventListener("menubutton", onMenuKeyDown, false); //never fires
alert("triggered"); //does fire
});
// search button press
function onSearchKeyDown() {
//change to search page
alert("search");
$.mobile.changePage("#page4", {transition: "pop"});
}
//menu button press
function onMenuKeyDown() {
//change to start page
alert("menu");
$.mobile.changePage("#page1", {transition: "pop"});
}
Here is the solution if anyone else has this problem.
via https://stackoverflow.com/a/9739986/799876
A few lines up from the bottom of cordova.js, there is the line
Change it to
For me, this fixed the menubutton and searchbutton events with phonegap & jQuery Mobile.