Question

How to use backbutton functionality using phone gap.

I saw many doc but I am not getting what to do. I want whenever I will click backbutton , it should go in previous state.

Was it helpful?

Solution

HERE you've documentation about backbutton in different mobile platforms.

EVENTS --> BACKBUTTON

Example:

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

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

    // Call onDeviceReady when Cordova is loaded.
    //
    // At this point, the document has loaded but cordova-1.7.0.js has not.
    // When Cordova is loaded and talking with the native device,
    // it will call the event `deviceready`.
    //
    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    // Cordova is loaded and it is now safe to call Cordova methods
    //
    function onDeviceReady() {
        // Register the event listener
        document.addEventListener("backbutton", onBackKeyDown, false);
    }

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

    </script>
  </head>
  <body onload="onLoad()">
  </body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top