Cordova - Back Button



Handling Back Button

You will usually want to use Android back button for some app functionality like returning to previous screen. To be able to implement your own functionality, you first need to disable exiting the app when the back button is pressed.

document.addEventListener("backbutton", onBackKeyDown, false);  
function onBackKeyDown(e) { 
   e.preventDefault(); 
   alert('Back Button is Pressed!'); 
}

Now when we press the native Android back button, the alert will appear on the screen instead of exiting the app. This is done by using e.preventDefault().

Event Back Button
Advertisements