Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-9664

"backbutton" event not fired for Windows Phone, app exits ["backclick" on WinJS.Application... as workaround]

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 5.3.2
    • None
    • cordova-windows
    • None
    • Windows platform windows@4.1.0

    Description

      The "backbutton" event is not fired for Windows, the app exits instead.

      Reproduce as follows:

      1. Run the commands:
      cordova create test
      cd test
      cordova platform add windows

      2. Edit www/js/index.js and insert the following lines after "app.receivedEvent('deviceready');":
      document.addEventListener('backbutton',function(e)

      { alert('Back button'); }

      , false);
      if (window.WinJS && window.WinJS.Application) {
      window.alert = navigator.notification.alert;
      WinJS.Application.addEventListener("backclick", function (e)

      { alert('Back button from *WinJS*'); // Prevent the default behavior by returning true. e.preventDefault() doesn't cancel the external code. return true; }

      );
      }

      3. Run command:
      cordova build windows

      4. Open Visual Studio 2015 with platforms\windows\CordovaApp.sln, select "CordovaApp.Phone (Windows Phone 8.1)" as "Startup Project". Run the "Emulator 8.1 WVGA" to test.

      5. Press Back button on emulator device. The message "Back button from WinJS" will be shown and not "Back button".

      The additional lines to add "backclick" event using WinJS.Application is a workaround that I found to work as a replacement. If those lines are removed, the app will effectively exit when the Back button is pressed. It works just fine with e.g. Android (test with "cordova platform add android" and "cordova run android") to verify.

      Attachments

        Issue Links

          Activity

            People

              viras Viras
              minduch Christopher Mindus
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: