Skip to content

Instantly share code, notes, and snippets.

@apeckham
Created August 17, 2012 18:37
Show Gist options
  • Save apeckham/3381440 to your computer and use it in GitHub Desktop.
Save apeckham/3381440 to your computer and use it in GitHub Desktop.
phonegap android -- back button hides suggestions, or goes back one page, or exits app
// doesn't work: when keyboard is shown, back button hides keyboard. hitting back button again exits app w/o triggering this event
$(document).on('backbutton', function () {
console.log('back pressed');
if ($.mobile.activePage.find('.suggestions').children().length > 0) {
console.log('hide suggestions');
var $input = $.mobile.activePage.find('input');
$input.val('');
$input.autocomplete('clear');
return;
}
if ($.mobile.urlHistory.activeIndex > 0) {
console.log('go back');
window.history.back();
return;
}
console.log('exit app');
navigator.app.exitApp();
});
// better solution
$(window).resize(function () {
if ($.mobile.activePage) {
var $input = $.mobile.activePage.find('.search-form input');
$input.val('');
$input.autocomplete('clear');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment