简体   繁体   English

Windows Phone PhoneGap应用后退按钮问题

[英]Windows Phone PhoneGap app back button issue

I am developing Windows Phone PhoneGap app. 我正在开发Windows Phone PhoneGap应用程序。 When clicking hardware back button, It is going to the previous page using history.go(-1); 单击硬件后退按钮时,将使用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 . 以上答案可能适用于Windows Phone 7,但不适用于Windows Phone 8.1。 For override back-button in windows phone 8.1 we can use WinJS api. 对于Windows Phone 8.1中的覆盖后退按钮,我们可以使用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.
     }
   }
}   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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