iPhone Mobile Safari: Force keyboard open

后端 未结 5 1827
迷失自我
迷失自我 2021-02-05 00:52

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.

<
相关标签:
5条回答
  • 2021-02-05 01:33

    Try:

    $('#element').blur().focus();
    

    or if that does not work:

    $('#element').focus().blur().focus();
    

    blur() eliminates the focus and focus() brings it back. For some reason, it works every time compared to focus() working once in a while on its own.

    0 讨论(0)
  • 2021-02-05 01:41

    Maybe these links can help you:

    • http://4pcbr.com/topic/how_to_open_keyboard_on_ipad_with_js (not working anymore)

    • http://jgestures.codeplex.com

    0 讨论(0)
  • 2021-02-05 01:42

    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();
    }
    
    0 讨论(0)
  • 2021-02-05 01:43

    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);
    
    });
    
    0 讨论(0)
  • 2021-02-05 01:49

    This should do what you want:

    $("#element").focus().click();
    
    0 讨论(0)
提交回复
热议问题