Search code examples
javascriptwindows-phone-7cordovacordova-2.0.0

"backbutton" event won't fire


I am attempting to build a phonegap app for Windows Phone 7. I am trying to follow the documentation for the "backbutton" event (http://docs.phonegap.com/en/2.0.0/cordova_events_events.md.html#backbutton), but I can't seem to get it to work.

The "deviceready" event fires, but the "backbutton" event does not. When compiling and running in Visual Studio Windows Phone emulator the onDeviceReady function is called and "Device ready" is logged, but when the emulator back button is pressed the application exits and nothing is logged in the console. When the back button is pressed the OnBackKeyDown function should run.

copy of the code from the offical doc:

<html>
    <head>     
        <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
        <script type="text/javascript">
            function onLoad() {
                document.addEventListener("deviceready", onDeviceReady, false);
            }
            function onDeviceReady() {
                console.log("Device ready");
                document.addEventListener("backbutton", onBackKeyDown, false);
            }
            function onBackKeyDown() {
                console.log("Back button pressed");
            }
        </script>
    </head>
    <body onload="onLoad()">
        <div></div>
    </body>
</html>

Solution

  • The fix has been committed here: https://github.com/purplecabbage/incubator-cordova-wp7/commit/d04b87abb3c3822ef25438e1353a1d7d2e0d6628

    You will need to wait for 2.1.0 to be released early next week, or build your app from source-code, in the meantime.