Reputation: 1231
I am working on a phonegap (version 6+) based hybrid app. I recently noticed that on pressing the android mobile hardware back button, the phonegap "backbutton"
event is not fired under the following circusmstances:
"backbutton"
event fired "backbutton"
event is not fired and the select element does not trigger a blur
or focusout
eventOn googling i can see that this seems to be a known issue, but, my question is: There is a workaround for the first case where i can listen to the window resize
event. But for the second case i.e. the select element close, I am not sure how to capture that event? blur
and focusout
don't work. Is there any workaround or solution to this?
Thanks for any help.
Upvotes: 1
Views: 575
Reputation: 2384
If you want a workaround solution for this then you can set function to check on click if select box is open or close and then if its open false set variable to true and closed then false like below.
//set variable global
var clickedDropdown;
$("select").bind("click", function () {
var clickedDropdown = $(this);
if (clickedDropdown.data('open') == false) {
clickedDropdown.data('open', true);
console.log(this.name + " open");
//Your code goes here
} else {
clickedDropdown.data('open', false);
console.log(this.name + " closed");
//Your code goes here
}
});
Updated
$(document).ready(function(){
setTimeout(function(){
document.addEventListener('backbutton', function(e){
if (clickedDropdown.data('open') == true) {
$( "select" ).trigger( "click" );
//or
//You can set blur or focusout event if dropdown already open
} else {
//You can set another function for backbutton pressed event
}
});
},500);
});
Upvotes: 1