iPad HTML Focus
Unfortunately, focusing is not possible with the iPad. The only way the focus will be placed in the desired field is when the user 'clicks' on the desired field.
Update 2015-01-08:
As explained in this answer by Matt:
... iOS will only allow focus to be triggered on other elements, from within a function, if the first function in the call stack was triggered by a non-programmatic event. In your case, the call to setTimeout starts a new call stack, and the security mechanism kicks in to prevent you from setting focus on the input.
apchester
Love to program in ruby and objective-C, mostly with rails and Cocoa.
Updated on August 07, 2022Comments
-
apchester over 1 year
I have an issue with focusing a text field on the iPad. Where I use:
$(document).bind("click",function(event) { alert('click'); focusTextArea(); });
The focus is set to the text area, and a keyboard appears. However when called with touchend,
focusTextArea
is not called and the keyboard is not made visible. MyfocusTextArea
function is:function focusTextArea() { $('#textArea').focus(); }
Does anybody know why this occurs, and how I might be able to get this to work?
TIA,
Adam
-
FarFigNewton almost 13 yearsAre you using the jquery plugin touchend?
-
Tim almost 13 yearsCan you elaborate on what you meant by "when called with touchend"?
-
apchester almost 13 years@guanome- not using any plugins, just standard jquery.
-
apchester almost 13 years@tim, Sorry I meant replacing the click event argument of bind with the touchend event.
-
Kheldar over 12 years
-
Ads over 10 yearsI got around this by adding a div that covered the whole display area with some basic instruction in the middle "Tap to Begin". Then bound a "tap" event to the div. The tap then hid the div and set focus to the textbox. That was the only way I could find to get around this crazy problem.
-
-
robocat almost 12 yearsAdditionally, in an onclick event for any element, you can call focus() to another input.
-
Jörn Berkefeld about 11 yearsnot completely true: if the focus is triggered within the callback of a click event on another INPUT field, this actually works (unless you have an animation in between which seems to interrupt this option again...). so yes it does kinda (not) work, sort of :P
-
ddlab about 10 yearsUnfortunately, 'touchend' doesn't work in every case, but 'mouseup' does ! Please tryout and find your best practice.
-
Daft over 9 yearsAny references to support that Bob? I know myself first hand that focus doesn't work properly. I'm just wondering if Apple has said anything about it themselves.