199r35Ox
199r35Ox

Reputation: 21

Windows Phone 8 & Phonegap: how to close app with back button

I use phonegap to create Windows Phone 8 app

Now, I'm done with everything but i can't exit the application with back button.
I had used navigator.app.exitApp(); but it's now working. Does it work on Windows Phone?

It's working on Android and Blackberry.

Upvotes: 1

Views: 1634

Answers (1)

funwhilelost
funwhilelost

Reputation: 2010

navigator.app is only available on Android and Blackberry. To exit from the app in Windows Phone 8 using the back button you need to remove the back button event handler.

function onBackKeyDown(e) {
    e.preventDefault();
    window.history.go(-1);
}

function onPageChange() {
    if(window.location.hash != "#/") {
        // add our event listener for sub pages, this will allow us
        document.addEventListener("backbutton", onBackKeyDown, false);
    } else {
        // remove the event listener so the back button will exit the app
        document.removeEventListener("backbutton", onBackKeyDown, false);
    }
}

Upvotes: 1

Related Questions