Back button handler in Cordova Android 4.0.0 app with non-obstructing pedestrian crossing

I am using the following code to capture the back button in a Cordova Android 4.0.0 application using 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!");
}
      

Run codeHide result


The button handler is called, but using e.preventDefault () does not work and the application still exits. Does anyone know why or a workaround for this?

+3


source to share





All Articles