iPhone Mobile Safari: Force keyboard open

35,010

Solution 1

Maybe these links can help you:

Solution 2

Try this

Tested on Safari iPhone 7 & iPhone 6 Plus, Android 4.4

and it opened iOS virtual keyboard successfully when I touched the button.

condition

1) make a Button to trigger keypress event => $('.btn_abc')

2) make a text input tag, and set the ID to this element => $('#search_input')

$( document ).ready(function() {

  var focusTextField = function(){
    console.log("focusElement");
  };

  var onKeypressHandler = function(){
    console.log("* * * keypress event handler")
    $('#search_input').blur().focus();
  };

  var onClickHandler = function() {
    $('.btn_abc').trigger('keypress');
  };

  $('#search_input').bind('focus', focusTextField);
  $('.btn_abc').bind('click', onClickHandler);
  $('.btn_abc').bind('keypress', onKeypressHandler);

});

Solution 3

Turn that button into an input field then instantly swap focus to the main input field. They keyboard will open and stay opened. Below is an example using a button like you asked, placing a transparent input field over the button the user clicks. Tested on an iPhone 4 (iOS 6/7) and an HTC Windows phone.

The input you want the user to focus on:

<input id="main" />

The button the user presses (with input field overlayed using css):

<a>Button</a><input onfocus="FocusMain()" />

Swap focus instantly:

function FocusMain()
{
    $("#main").focus();
}
Share:
35,010
KrazyKen04
Author by

KrazyKen04

Updated on August 03, 2022

Comments

  • KrazyKen04
    KrazyKen04 almost 2 years

    This is an HTML / CSS / JS (jQuery) iPad app. I've got a button, that slides down an input form. I'd like to focus the user on the input, and then launch the keyboard.

    This is what I'm working with, but doesn't work:

    $('#myFormField').focus();
    

    This does indeed focus the input, but fails to launch the keyboard. Is it just not possible (for security reasons or whatever)?

    Is there a way to force or simulate a user tapping the input (or anything for that matter)?

  • Vitim.us
    Vitim.us over 12 years
    Doesn't work! I tried also, using setTimeout delay, and triggering the ontouchstart and ontouchend to simulate a touch on a input, but no progress.
  • Zathrus Writer
    Zathrus Writer over 11 years
    this will not work... by design, phones do not allow showing keyboard on focus, a person needs to click on the input directly or use a focus() from within an onClick() event on another element
  • Zathrus Writer
    Zathrus Writer over 11 years
    same as above - this will not work... by design, phones do not allow showing keyboard on focus, a person needs to click on the input directly or use a focus() from within an onClick() event on another element
  • Zathrus Writer
    Zathrus Writer over 11 years
    sorry, I have just realized that iPhone and iPad from iOS version 5 have ability for this to work, but Android certainly will chew on this
  • Collective Cognition
    Collective Cognition almost 11 years
    It's worth noting that this DID work at the time of posting, on the version of Safari which was current then.
  • ceejayoz
    ceejayoz almost 11 years
    A demo would go a long way.
  • t q
    t q over 9 years
    using jgesture to auto open keyboard but this doesnt work jQuery('#myTextBox').trigger("tapone");
  • Jordan Eldredge
    Jordan Eldredge about 7 years
    First link is returning 404.
  • user1113531
    user1113531 almost 7 years
    This worked for me on iPhone6 Plus, safari, ios 10.3.1.
  • storsoc
    storsoc about 6 years
    Excellent. Working for me on iOS 11.3 (on an iPhone 6P and iPad Air, if that's of any consequence.)
  • user2108555
    user2108555 about 4 years
    For me, using just $('objId').focus(); did the trick. I’m using it for a clear text box value button that originally cleared out the text box and the keyboard would annoyingly disappear too now the keyboard stays open. Awesome and thanks 👍