1

How does one in iOS (iPad/iPhone/iPod) to force the focus on an input element when the DOM is ready, with jQuery?

I've got a barcode webpage, that needs the focus to be immediately on a textfield.

I've found jQuery will do just fine for IE,Firefox,Chrome,Safari,Android but iOS mobile Safari, and iOS mobile Chrome won't let me focus on a textfield when the DOM is ready.

This is what I have so far:

$j(document).ready(function() {
    $j('#barcode').focus();
});

Any ideas, guys/gals?

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
user2730049
  • 11
  • 1
  • 3

1 Answers1

4

It is not possible on Mobile Safari and presumably Chrome on iOS. See the following duplicate SO questions:

Running this fiddle in Mobile Safari or Chrome on iOS will confirm this answer.

$("input").focus(); // Does not focus input in Mobile Safari or Chrome on iOS.

This code has been tested (and failed) in Mobile Safari and Chrome on iOS on the following devices:

  • iPhone 4 running iOS 7 beta 6
  • iPad 2 running iOS 6.1.3
  • iOS Simulator running iOS 7 beta 5
Community
  • 1
  • 1
JWK
  • 3,345
  • 2
  • 19
  • 27