简体   繁体   English

Cordova Windows Phone后退按钮覆盖不触发

[英]Cordova Windows phone back button override not firing

I have an universal app with Cordova and PhoneJS and build it with Phonegap for iOS, Android and Windows Phone. 我有一个与Cordova和PhoneJS通用的应用程序,并使用适用于iOS,Android和Windows Phone的Phonegap构建它。 The Windows Phone style removes the back button on views to navigate back. Windows Phone样式将删除视图上的“后退”按钮以向后导航。 When I press the hardware back button, the app exits. 当我按下硬件后退按钮时,该应用程序退出。

Thats why I want to override the back button functionality. 这就是为什么我要覆盖后退按钮功能。 I found a lot of documentation which states that you need to register on the ' backbutton ' event on ' deviceready ' after Cordova loads. 我找到了很多文档,其中指出,在Cordova加载后,您需要在deviceready上的backbutton事件上进行注册。

The ' on load ' and ' deviceready ' events are invoked successfully. 成功调用了“ 加载 ”和“ deviceready ”事件。 The problem is that the back button event is not invoked and the app still exits. 问题在于后退按钮事件没有被调用,应用程序仍然退出。

Versions: 版本:

npm list -g cordova
...\AppData\Roaming\npm
└─┬ phonegap@5.3.7
  └── cordova@5.4.0

Device: 设备:

  • Microsoft Lumia 640 LTE 微软Lumia 640 LTE
  • Windows Phone 8.1 Update 2 Windows Phone 8.1更新2

Code: 码:

 // Is invoked function onLoad() { document.addEventListener("deviceready", onDeviceReady, false); } // Is invoked function onDeviceReady() { document.addEventListener("backbutton", onBackButton, false); } // Is not invoked function onBackButton(){ debugger; } 
 <body onload="onLoad()"> </body> 

I found out that the included PhoneJS uses WinJS . 我发现随附的PhoneJS使用WinJS With that I could set the ' onbackclick ' action. 这样,我可以设置“ onbackclick ”操作。

 function onLoad() { document.addEventListener("deviceready", onDeviceReady, false); } function onDeviceReady() { // Check if WinJS api is available if(WinJS){ WinJS.Application.onbackclick = function (e) { MyApp.app.navigationManager.back(); // Return true otherwise it will close app. return true; } } } 
 <body onload="onLoad()"> </body> 

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

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