Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
51 Views

backbutton event not firing in cordova windows phone app

Jump to solution

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;

};
Tags (2)
0 Kudos

Accepted Solutions
Highlighted
51 Views

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.

View solution in original post

0 Kudos
6 Replies
Highlighted
Employee
51 Views

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 Kudos
Highlighted
Beginner
51 Views
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 Kudos
Highlighted
52 Views

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.

View solution in original post

0 Kudos
Highlighted
Beginner
51 Views

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 Kudos
Highlighted
Beginner
51 Views
please help me I can not publish my app for windows phone 8.1 , I have tried everything ...
0 Kudos
Highlighted
Beginner
51 Views

Hi, Pablo,

Could you please summarize what did not work.

 

0 Kudos