Credit to devdocs.io

cordova

cordova

backbutton

The event fires when the user presses the back button.

document.addEventListener("backbutton", yourCallbackFunction, false);

Details

To override the default back-button behavior, register an event listener for the backbutton event, typically by calling document.addEventListener once you receive the [deviceready](events.deviceready.html) event. It is no longer necessary to call any other method to override the back-button behavior.

Supported Platforms

  • Amazon Fire OS
  • Android
  • BlackBerry 10
  • Windows Phone 8

Quick Example

document.addEventListener("backbutton", onBackKeyDown, false);

function onBackKeyDown() {
// Handle the back button
}

Full Example

<!DOCTYPE html>
<html>
  <head>
<title>Back Button Example</title>

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

// 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() {
}

</script>
  </head>
  <body onload="onLoad()">
  </body>
</html>

© 2012-2015 The Apache Software Foundation
Licensed under the Apache License 2.0.
http://cordova.apache.org/docs/en/5.4.0/cordova/events/events.backbutton.html