Skip to content

Instantly share code, notes, and snippets.

@fabiancarlos
Last active August 29, 2015 13:57
Show Gist options
  • Save fabiancarlos/9748385 to your computer and use it in GitHub Desktop.
Save fabiancarlos/9748385 to your computer and use it in GitHub Desktop.
Back like button on Phonegap w/ AngularJS
// add a element with id="homegap" on the template home of the app
app_helper = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function(){
// back button exit the app
document.addEventListener("backbutton", app_helper.onBackKeyDown, false);
},
onBackKeyDown: function(){
var homepage = document.getElementById('homepage');
if (homepage){
navigator.app.exitApp();
}else{
navigator.app.backHistory();
}
},
};
app_helper.initialize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment