简体   繁体   中英

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.

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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM