Created
September 19, 2016 23:10
-
-
Save diogomachado/b3d72a9c03056d2e4fd843c57aff5da2 to your computer and use it in GitHub Desktop.
backbutton - Cordova (Está usando ngCordova, mas pode fazer um confirm nativo também)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fica escutando o evento do botão voltar | |
// //////////////////////// | |
document.addEventListener("backbutton", function(){ | |
// Se estou na home, então pergunto se quer sair do app | |
if ($location.path() == '/'){ | |
// Mando uma mensagem na cara do usuário, perguntando se quer sair | |
$cordovaDialogs.confirm('' , 'Deseja sair do aplicativo?', ['Sim','Não']).then(function(buttonIndex) { | |
// no button = 0, 'OK' = 1, 'Cancel' = 2 | |
if (buttonIndex == 1){ | |
navigator.app.exitApp(); | |
} | |
}); | |
} | |
else{ | |
navigator.app.backHistory(); | |
} | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment