How To Disable Android Back Button Handler In Onsen-ui Phonegap?
Solution 1:
This is explained in Onsen UI docs: http://onsen.io/reference/ons.html#methods-summary
Just use the method ons.disableDeviceBackButtonHandler()
and it will be disabled. You can use ons.enableDeviceBackButtonHandler()
to enable it again.
Solution 2:
This works for me in onsen2...I have it in my app.js
ons.ready(function () {
ons.disableDeviceBackButtonHandler();
document.addEventListener('backbutton', function () {}, false);
});
Solution 3:
Try to leave the function empty. This works perfect for me.
document.addEventListener("backbutton", androidBackKey, false);
var androidBackKey = function(){
//stay empty
};
Solution 4:
Try this:
function onLoad()
{
document.addEventListener("deviceready",onDeviceReady,false);
}
function onDeviceReady()
{
document.addEventListener("backbutton",noth,false);
}
function noth()
{
}
Solution 5:
Use this if you're using a navigator:
myNavigator.getDeviceBackButtonHandler().setListener( stopButton );
function stopButton(e) {
try{
myNavigator.popPage();
}
catch (err){
// event.callParentHandler();
console.log( "Stopping...." + e);
}
}
It's another listener handled by ONSEN-UI itself that quit the app. So add a listener attached to document will not stop the app from exiting. To understand it's flow, you may check out onsenui_all.js to check out the source code.
Post a Comment for "How To Disable Android Back Button Handler In Onsen-ui Phonegap?"