Created
August 17, 2012 18:37
-
-
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
This file contains 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
// 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