Android - html input loses focus when soft keyboard opens (ASP.net) Android - html input loses focus when soft keyboard opens (ASP.net) asp.net asp.net

Android - html input loses focus when soft keyboard opens (ASP.net)


I discovered this is nothing to do with ASP.net or ViewState.

When the Android keyboard appears, the browser window is resized - triggering the resize event.

I was running something similar to the following:

// Move the navigation on resize$(window).bind('resize', function() {    if(maxWidth <= 710px) {        $('.nav').after($('.main-content'));    }});

This moved the navigation in the DOM. I guess this redraws the DOM and so causes anything in the DOM to lose focus. I stopped this from happening on resize - making it only happen on initial page load instead.


I had a similar problem, my approach to prevent resize to execute if input is in focus solved the problem:

$(window).bind('resize', function() {    if ($("input").is(":focus")) {        // input is in focus, don't do nothing or input loses focus and keyboard dissapears    } else {        // do whatever you should do if resize happens    }});


I have find other solution

First you have to create a function

function getFocus(campo){    $(window).bind('resize', function() {        if(windowWidth <= 1025) {            $(campo).focus();        }    }); }   

and when you click in an input you call the function

$('input').click(function(){    getFocus(this); });

This works for me