Software Archive
Read-only legacy content

backbutton event not firing in cordova windows phone app

Sam_Deepak
초급자
1,548 조회수

I am trying to test my cordova app which has been built using Intel XDK for windows phone.

I am testing the app in windows phone 8.1 emulator, the backbutton event is not firing, instead it exits the app.

And I tried with some suggestions I read from internet to use winjs to capture backclick event which is not also working.

Please help me resolve this problem.

Code to capture backbutton:

document.addEventListener('backbutton', function(){
 // Code to handle;
 e.preventDefault();
}, false);    

With WinJS:

window.WinJS.Application.onbackclick = function (e) {
 // Code to handle

 e.handled = true;
 return true;

};
0 포인트
1 솔루션
PaulF_IntelCorp
1,548 조회수

Sam, also, try including this script in the front of your app, there may be some issues related to the strict security model that Microsoft imposes on that webview > https://github.com/xmnboy/xdk-win8x-compat.js < this will also allow you to use alert() in your code for debugging on a real device.

원본 게시물의 솔루션 보기

0 포인트
6 응답
Amrita_C_Intel
1,548 조회수

Hello Sam Deepak,

I would recommend you to try building our one of the existing samples and watch the response of the back button.

0 포인트
Sam_Deepak
초급자
1,548 조회수
Hi Amrita, I am not using app framework's navigation mechanism and it's history management. I am using a single page app where I have coded my own technique if going back to previous screens which is specific to my app. So while I faced this issue, I just tried a small empty app where I am trying to capture back button cordova event which is not working. Then I Googled for the answers and tried almost everything, but no hopes. That's why if I try an existing sample from Intel XDK tool, that will not suit my case. Please help me identify the problem if I have to capture the back button event in Windows cordova build in an empty app.
0 포인트
PaulF_IntelCorp
1,549 조회수

Sam, also, try including this script in the front of your app, there may be some issues related to the strict security model that Microsoft imposes on that webview > https://github.com/xmnboy/xdk-win8x-compat.js < this will also allow you to use alert() in your code for debugging on a real device.

0 포인트
Sam_Deepak
초급자
1,548 조회수

Hi Paul,

Thanks. It worked. Here is what I can summarize.

Basically in my previous question, you have referred to a plugin from MSOPENTECH (winstore-jscompat,) which made javascript plugins work. But backbutton was still the issue I was facing. Then, I came to know that backbutton event from cordova has been ignored in windows phone 8.1 runtime and it delivers the hardware backbutton event to a Microsoft javascript library called WinJS. So I used it, but still was the issue unresolved. Now after referring the plugin you have referred in your reply (https://github.com/xmnboy/xdk-win8x-compat.js) which is once again customized and corrected by Intel XDK team (this is what I read there in this link), the backclick event works.

So the solution is to refer xdk-win8x-compat.js before all scripts. And backclick event is fired only in conjuction with this library. So for windows phone build, it is required to add this library before the script that starts the app. And for backbutton event in windows phone, it is required to add the base library from WinJS, i.e., you can see in the attached zip which is what I used.

 

0 포인트
Pablo_A_
초급자
1,548 조회수
please help me I can not publish my app for windows phone 8.1 , I have tried everything ...
0 포인트
Sam_Deepak
초급자
1,548 조회수

Hi, Pablo,

Could you please summarize what did not work.

 

0 포인트
응답