javascript - Auto Show Soft Keyboard on mobile web browser - Stack Overflow

I want to make the soft keyboard show on $( document ).ready(function() {....});here's my html c

I want to make the soft keyboard show on

$( document ).ready(function() {
....
});

here's my html code:

<form id="typerForm">
<input id="typer" style="position:relative; left:-100em;"/>
</form>

<div id="myInput" style="border:2px solid #4AA; width:6em; height:1em; font-size:2em"></div>
<div style="height:20em; background-color:#eee">

</div>    

and here's my javascript code:

$('body').click(function() {
    $('#typer').focus();
    $('#typer').select();

});


$('#typerForm').submit(function() {
    //alert("submit");
    setTimeout("$('#typer').focus();", 1000);
    return false;
});

$('#typer').bind('keyup', function(e) {
    var input = $.trim($(this).val());
    // some lines of code..
    $('#myInput').text(input);
    //...
    //$(this).val('').focus(); // clean up
});

or you can look at my code here /

my code works to show the keyboard on mobile web browser when i click on somewhere or click on the input text. And what i want is show keyboard automatically when the page ready or finish loading

I want to make the soft keyboard show on

$( document ).ready(function() {
....
});

here's my html code:

<form id="typerForm">
<input id="typer" style="position:relative; left:-100em;"/>
</form>

<div id="myInput" style="border:2px solid #4AA; width:6em; height:1em; font-size:2em"></div>
<div style="height:20em; background-color:#eee">

</div>    

and here's my javascript code:

$('body').click(function() {
    $('#typer').focus();
    $('#typer').select();

});


$('#typerForm').submit(function() {
    //alert("submit");
    setTimeout("$('#typer').focus();", 1000);
    return false;
});

$('#typer').bind('keyup', function(e) {
    var input = $.trim($(this).val());
    // some lines of code..
    $('#myInput').text(input);
    //...
    //$(this).val('').focus(); // clean up
});

or you can look at my code here http://jsfiddle/7urry794/

my code works to show the keyboard on mobile web browser when i click on somewhere or click on the input text. And what i want is show keyboard automatically when the page ready or finish loading

Share Improve this question edited May 23, 2017 at 14:32 adn asked May 23, 2017 at 7:15 adnadn 4303 gold badges7 silver badges21 bronze badges 1
  • Please provide code in your question. Else as soon as your link is broken, nobody will be able to re-use the help provided to solve your problem – Nuageux Commented May 23, 2017 at 8:52
Add a ment  | 

2 Answers 2

Reset to default 3

you can use below code to open keyboard on iOS or Android There are a couple of ways I know of to get around this:

prompt() opens the keyboard

If you trigger the .focus() from within a .click() event (e.g. from opening your dialog), the keyboard shows up

Hope it might help

You can do this by calling focus() then click() on the input, but only if the script is initiated by user input. All attempts to get this to work from an onload handler with no user interaction FAILED :-( Beware of endless loops if your script is triggered by an onclick() on a containing element. The script below is working for me on Chrome for android 58 and Safari mobile 602.1, when called from an onclick().

function onSomethingOtherThanLoad(event){
    // get the input
    var target = document.getElementsByTagName("input")[0];
    if (event.target != target) {
        target.focus();
        target.click();
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744684046a4587804.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信