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

后端 未结 6 1667
梦谈多话
梦谈多话 2020-12-10 02:05

I\'ve written a web-page login form in ASP.net.

Using a Nexus 4, stock Android 4.2.1, native Chrome browser - when I click on the fields,

6条回答
  •  无人及你
    2020-12-10 02:29

    I had custom code in my $(window).resize(..) that I wanted to keep, and I wanted to restrict this workaround to only the specific use case being impacted (Android mobile only, Text Input or TextArea focus), so I came up with this:

    function isAndroidTextInputFocus() {
        var userAgent = navigator.userAgent.toLowerCase();
        var isAndroid = userAgent.indexOf("android") != -1;
    
        var result = (isAndroid && 
                 ($("input[type=text]").is(":focus") || $("textarea").is(":focus"))     
               );
    
        return result;
    }
    

    and then I tweaked my $(window).resize(..) like this:

    $(window).resize(function(e) {
        if (!isAndroidTextInputFocus()) {       
            // ... Proceed with my custom Window Resize logic
        }
    }); 
    

提交回复
热议问题