Chrome for iOS(iPad / iPhone)不会触发输入的焦点事件 [英] Chrome for iOS (iPad/iPhone) does not fire focus event for inputs

查看:859
本文介绍了Chrome for iOS(iPad / iPhone)不会触发输入的焦点事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $(document).on( {
focus:function(){keyboardOpened = true;},
blur:function(){keyboardOpened = false;}
},'input'); //捕获任何输入元素上的所有焦点和模糊事件

用于防止用户执行某些操作(例如忽略大小调整事件)。

它适用于所有浏览器,但iOS上的Chrome除外。我已经在网站上包含了Firebug Lite,但没有任何错误,只是这些事件从未被解雇,网络在打开SW键盘时无法正常工作。



小提琴: http://jsfiddle.net/WYULR (点击输入并查看提醒)



任何人都知道这个原因或解决方法吗?

解决方案

:(我的解决方案是检测是否使用ipad + chrome:

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

我试过 https://github.com/gabceb/jquery-browser -plugin + webkit类型区分代码在这里找到如何检测Chrome和Safari浏览器(webkit),但我无法得到这个工作。



如果ipad + chrome,应用一个'点击'事件的领域做同样的事情...这是唯一好,如果你将有唯一的焦点是从用户点击,因为调用.focus()不会触发它...但在这种情况下你可以在.focus()之后调用通过click事件赋值的函数。这似乎有点hackish所以我决定测试香草焦点事件,并证明它也没有射击。

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?

解决方案

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.

这篇关于Chrome for iOS(iPad / iPhone)不会触发输入的焦点事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆