11

Possible Duplicate:
iPad HTML Focus

Does anyone know how to get the focus() method from jquery to work on the ipad, or perhaps a workaround? What I'm trying to do is to get the keyboard to pop up on a webpage since I have jquery capturing keystrokes to perform events. However, without a textbox on the page I don't know how to get the keyboard to pop up. Now that I have the textbox on the page, I'm trying to use jquery to set the focus to the textbox so the keyboard pops up. On top of this, I'm setting the textboxs style to display:none, so that the focus goes to the textbox but it's not seen, so the functionality appears to work. However, focus() is broken on the ipad! Can anyone help me?

Community
  • 1
  • 1
JesseBuesking
  • 6,496
  • 4
  • 44
  • 89
  • I'm sorry was what I meant. Is there really no workaround for this? The site I've been designing is kind of built around having this work, so I'm hoping I can make this happen somehow. – JesseBuesking Mar 13 '11 at 04:13
  • No; because Apple doesn't want the keyboard to appear *except* on user demand. Though, sadly, I can't find a document to *prove* that. My comments are based purely on empirical observation, which is a shame. – David Thomas Mar 13 '11 at 04:16

3 Answers3

7

Unfortunately, the only way to get a keyboard to show, is during a user initiated event. This is something I've been fighting with myself as of late.

Below, ilumin has a good solution, but it's not the only one. Basically, from what I've found, as long as your are performing your .focus() function call inside of a user event (such as mouseup, or any of the touch events [which is probably preferred for a touch device]), then you shouldn't have a problem.

To an extent I understand why Apple made this limitation, but at the same time, it has made my work very challenging.

NeoNexus DeMortis
  • 1,286
  • 10
  • 26
0

Unfortunately, you will only see the keyboard pop up when you focus in a text field. See this answer.

Community
  • 1
  • 1
halfpastfour.am
  • 5,764
  • 3
  • 44
  • 61
0
<input>
<a href="#" class="label">Click</a>
$('.label').mouseup(function(){ $('input').focus(); });

it work on my project. just use "mouseup" to capture event and "focus" on input

via http://www.quora.com/Mobile-Safari-iPhone-or-iPad-with-JavaScript-how-can-I-launch-the-on-screen-keyboard

ilumin
  • 608
  • 12
  • 22
  • This works because you initiated the .focus() from a user initiated event (mouseup). It won't work when you use it from document ready or some other non-user initiated event (timeout, etc).. The highlighting box appears around the field, but no keyboard. – Ads Nov 29 '13 at 03:59