iOS 8 3rd party keyboards don't register javas

2020-07-01 12:05发布

问题:

When using a 3rd party keyboard like Swiftkey javascript events like keypress don't register. For example Google maps autocomplete won't work https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete

Seems like an iOS bug but any ideas on how I can get around this?

回答1:

You can just manually fire keypress events.

$textBox = $('#text_box') // We don't want to search the dom more than we have to.
setInterval(function(){
    $textBox.trigger('keypress')
}, 500)

This is definitely a messy solution, but it should get autocomplete to work, as well as other handlers that wait for keypresses.



回答2:

Would this work?

jQuery('#text_box').on('input propertychange paste', function() {
    // text has changed...
});

JSFIDDLE



回答3:

I found a solution using setInterval and the answered method from here Trigger Google Places Autocomplete

setInterval(function() {
if ($('input#mapSearch').is(':focus')) {
google.maps.event.trigger(document.getElementById('mapSearch'), 'focus', {});
}
}, 500);