Radek Pech
Radek Pech

Reputation: 3098

Chrome for iOS (iPad/iPhone) does not fire focus event for inputs

I have a simple detection if a software keyboard is opened on Android and iOS:

$(document).on({
    focus: function() { keyboardOpened = true; },
    blur: function() { keyboardOpened = false; }
}, 'input'); //catch all focus and blur events fired on any input element

It's used to prevent certain actions while user is writing a message (e.g. ignoring resize events).

It works on all browsers except for Chrome on iOS. I've included Firebug Lite on the site but there is no error, just the events are never fired and the web does not work correctly when opening SW keyboard.

Here is a fiddle: http://jsfiddle.net/WYULR (click the input and see an alert)

Anyone knows about a reason or workaround for this?

Upvotes: 2

Views: 2799

Answers (1)

J. Barca
J. Barca

Reputation: 555

I get this too :( My solution is to detect if ipad + chrome using :

var isCriOS = /CriOS/.test(navigator.userAgent);

I tried https://github.com/gabceb/jquery-browser-plugin + webkit type distinguishing code found here How to detect chrome and safari browser (webkit) but I couldn't get that to work.

If ipad+chrome, apply a 'click' event for the field to do the same thing ... this is only good if the only focus you will have is from user taps, as calling .focus() will not trigger it ... but in this case you could just call the function ascribed through click event after the .focus() . This seemed a bit hackish so I decided to test vanilla js .onfocus event and proved that it wasn't firing either.

Upvotes: 1

Related Questions