HUSTEN
HUSTEN

Reputation: 5197

Why this won't show keyboard on iPhone even when obj.focus() is used?

Javascript 1 is the action that will be invoked when a link is clicked.
It's working perfectly and it sets the value automatically, and focus the element.
Of course, iPhone's virtual keyboard appears because input text field is focused.

Javascript 1

jQuery(document).ready(function () {
    $(document).on('click', 'a#user', function()  {
        $(".box#input").val($(this).attr('value')); 
        var input = $(".box#input");
        $(document).scrollTop(input .offset().top - 45);
        input.focus();          
    });
 });

This Javascript 2 is the action that will be invoked when URL contains mode=1 and when it's loaded. This script does pretty much the same as above and working fine.
But one thing!! iPhone's keyboard won't appear even though input text field is focused.
It's really strange... Why? and How can I fix this?

Javascript 2

window.onload = function(){
    if(document.URL.indexOf("mode=1") >= 0){ 
        var input = $(".box#input");
        $(document).scrollTop(input .offset().top - 45);
        var v = input.val();
        input.val('');
        input.focus().val(v);
        input.focus();
    }
}

Upvotes: 1

Views: 2389

Answers (2)

djehring
djehring

Reputation: 1

input.focus() will activate the keyboard if you add the web page to the iOS home screen and access it from there

Upvotes: 0

Adam
Adam

Reputation: 2225

Normally the keyboard will not show unless there is some kind of user interaction (eg. clicking on an input field). You can however do this programmatically as you did above if you use a timeout.

setTimout(function(){
    input.focus();
}, 1);

Upvotes: 1

Related Questions