I'm trying to prevent the default behavior when someone presses the 'Back' button on an Android device. I have successfully bound to the event, and it is firing correctly, but I cannot prevent the default behavior. I have searched online through countless posts and according to all previous posts, my current solution should work, but it does not.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown(e) {
alert('back button triggered');
console.log(e);
e.preventDefault();
return false;
}
When the back button is clicked, I will get the alert, but it will not prevent the behavior. I have an Angular SPA application running in PhoneGap, so it usually mimics a browser's back behavior and changes the URL, therefore going to the previous page within the app.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown(e) {
alert('back button triggered');
console.log(e);
e.preventDefault();
return false;
}
When the back button is clicked, I will get the alert, but it will not prevent the behavior. I have an Angular SPA application running in PhoneGap, so it usually mimics a browser's back behavior and changes the URL, therefore going to the previous page within the app.





