- Overview
- The Command-line Interface
- Platform Guides
- Configuration Reference
- Embedding WebViews
- Plugin Development Guide
- Privacy Guide
- Domain Whitelist Guide
- Accelerometer
- Camera
- Capture
- Compass
- Connection
- Contacts
- Device
- Events
- File
- Geolocation
- Globalization
- InAppBrowser
- Media
- Notification
- Splashscreen
- Storage
This version of the documentation is outdated!
Click here for the latest released version.
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
- Android
- BlackBerry WebWorks (OS 5.0 and higher)
- Windows Phone 7 and 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>