Search code examples
androidvisual-studiowindows-phoneionic-framework

Ionic - disable hardware backbutton in Windows Phone 8.1 not working


I'm developing using IONIC framework. I'm having trouble with the hardware back button.

In android the hardware back button works perfectly, but the windows phone did not work out. When I use the back button on windows phone minimizes the application and returns the device's home.

This function only works on android:

 $ionicPlatform.registerBackButtonAction(function () {
            console.log("Not work in WP");
        }, 100);

help !!


Solution

  • I found solution.

    In site https://www.hoessl.eu/2014/12/on-using-the-ionic-framework-for-windows-phone-8-1-apps/ have a post calling -> Not fixed yet: Back Button

    Not fixed yet: Back Button

    With Windows Phone 8.0, listening on the “backbutton” event was pretty simple, just as with android. On WP8.1, this event is not triggered anymore. I haven’t figured out how to enable it yet. Any hint would be appreciated.

    But a user commented the solution. follows the passage that worked in my case

    Back Button Fix :

    Set your $ionicPlatform.registerBackButtonAction

    $ionicPlatform.registerBackButtonAction(function (evt) {
    if (evt && evt.type == ‘backclick’) {
    $ionicHistory.goBack();
    return true;
    }
    }, 100);
    

    Hookin WinJS and send it to Ionic :

    if(ionic.Platform.isWindowsPhone)
    {
    WinJS.Application.onbackclick = function (evt) {
    $ionicPlatform.hardwareBackButtonClick(evt);
    return true;
    }
    }
    

    Easy Fix, long time figuring it out