I would like to block the Android back button. I can trap the event and show alerts when the button is pressed, but I have trouble actually stopping the application from navigating back. The default code used for phonegap solutions does not seem to work on a Mendix based application. Does anyone know how to do this? The following code has been placed in a custom .js file inside the theme folder, which has been added to the components.js file.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
alert("On Load");
document.addEventListener("backbutton", didPressBackButton, false);
}
function didPressBackButton(event) {
alert("go back!");
// event.preventDefault(); //Does not block the backbutton
// event.stopPropagation(); //Does not block the backbutton
// return false; //Does not block the backbutton
} p.s: There have been similar questions before on this forum, but they were never conclusively answered. By removing unnecessary info from the question, I am hoping to get an answer that is more to the point. :-) p.p.s: An additional question which I do have: Where do I place and call the javascript code? By placing it in a custom .js file, It is only loaded once. This works if I want the behaviour everywhere. But when I need the behaviour in specific pages, this will not suffice. Using html widgets does not work either, since this results in the 'go back!' alert showing multiple times when entering a page multiple times. The number of alerts shown increases by one every time I press the back button on that page an additional time. Feedback on where to place the code would also be highly appreciated! p.p.p.s: The following code can be found in cordova.js when using remote inspection on an Android device. I suspect Mendix is inserting their own code in between the application and the Cordova event handlers:
↧