I am developing Windows Phone PhoneGap app. When clicking hardware back button, It is going to the previous page using history.go(-1); But when I am in initial page and click the back button It is navigating to the same page instead of killing the application. Any help is appreciated.
To configure back button you can use these functions:
// for exit app
navigator.app.exitApp();
// for back hsitory use
navigator.app.backHistory()
complete code :
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.is('#home')){
e.preventDefault();
navigator.app.exitApp();
}
else {
navigator.app.backHistory()
}
}, false);
}
Above answer may work with windows phone 7 but it is not working with windows phone 8.1 . For override back-button in windows phone 8.1 we can use WinJS
api.
Bind back button event on device ready.
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady(){
//check if WinJS api is available or not
if(WinJS){
WinJS.Application.onbackclick = function (e) {
//write your code here
return true; // you must return true otherwise it will close app.
}
}
}
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.