Back button handler in Cordova Android 4.0.0 App with crosswalk not preventing behavior

368 views Asked by At

I'm using the following code to capture the back button press in a Cordova Android 4.0.0 App with Crosswalk:

// Wait for device API libraries to load
//
function onLoad() {
  document.addEventListener("deviceready", onDeviceReady, false);
}

// device APIs are available
//
function onDeviceReady() {
  // Register the event listener
  document.addEventListener("backbutton", onBackKeyDown, false);
}

// Handle the back button
//
function onBackKeyDown(e) {
  e.preventDefault();
  alert("Back button pressed!");
}

The button handler is called but using e.preventDefault() is not working and the App is still being closed. Does anyone know why or a workaround for this?

0

There are 0 answers