- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Hi all,
when I hit the back button on the phone the application is closed and, when reactivated, it starts from the beginning.
I tried to capture the event in these two ways, that work well within the emulator. Do not go instead in the final build on phone.
//First try document.addEventListener("backbutton", backButtonPressed, false); function backButtonPressed() { } //Second try document.addEventListener("intel.xdk.device.ready",function() { intel.xdk.device.addVirtualPage(); },false); document.addEventListener("intel.xdk.device.hardware.back", function() { intel.xdk.device.addVirtualPage(); }, false);
It needs some plugins for the event, to make it work with Ionic?
thank you
- Balises:
- HTML5
- Intel® XDK
Lien copié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
For the Cordova backbutton event capture you do not need to provide any special plugins. To use that older intel.xdk event capture, you'll have to include the intel.xdk.device plugin.
I recommend you use the Cordova API. See this Stack Overflow post for some examples: http://stackoverflow.com/questions/22609411/over-ride-the-back-button-of-android-device-through-phonegap-in-javascript
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Hi, I'm using Ionic too and have the same problem: the app closes anyway. I'm using event.preventDefault() and
document.addEventListener("backbutton", onBackKeyDown, false);
Even though the code works and onBackKeyDown is called.
Is there any other way to prevent its default behaviour?
Ok, found this link in another topic http://www.gajotres.net/ionic-framework-handling-android-back-button-like-a-pro/ Gonna leave it here in case someone finds this topic first like I did :)
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Posting this as an update to trying out what was posted in the link. Here is an error I get if I use
$ionicPlatform.registerBackButtonAction(function(event) {
$ionicPlatform is not defined
and the other one is if I change it with ionic.Platform.
ionic.Platform.registerBackButtonAction is not a function
So I'm back to being stuck again.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
@Mario>
For me, it works good. I have:
document.addEventListener("backbutton", funNaoFazNada, false);
function funNaoFazNada() { }
Just it.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Anya-
If I understand correctly
- registering a backbutton event handler worked
- the backbutton event handler is called
- the app exits after the backbutton event handler is called
Are you using Crosswalk with your app?
Are you testing this using App Preview or have you built your app and installed it on a device?
Update:
Sorry I did not read more carefully; I did not realize you were using Ionic.
I see that you must have found this topic, where Paul pointed to this blog post.
If $ionicPlatform is undefined, there must be something wrong with how Ionic is configured or your code is being called before Ionic is initialized.

- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable