Disable zoom on input focus in Android webpage

后端 未结 30 1292
日久生厌
日久生厌 2020-12-02 05:17

Here\'s the dilema, I have a webpage (only for android devices) and in that page I have an input box (a text box specifically) and when it gets focus the browser zooms in. I

30条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 06:06

    I've been looking at this problem as it's something that's been irritating me with my HTML5 Android app. I can offer half an answer. That's to say, how to stop the page scaling when a text field is focussed.

    Requires Jquery Mobile:

    $('#textfield').textinput({preventFocusZoom:true});
    

    does exactly that.

    But, as I said, this only solves half of the problem. The other half is allowing the user to zoom the page again afterwards. The documentation I've found seems to suggest that

        $('#textfield').textinput({preventFocusZoom:false});
    

    or

    $('#textfield').textinput('option','preventFocusZoom',false);
    

    should un-set it, but I haven't managed to get either option to work. Not a problem if you're going to be taking the user to another page afterwards, but of limited use if, like me, you're just going to load content via AJAX.

    EDIT: Although aimed at IOS,

    $.mobile.zoom.disable();
    

    Also stops the zooming. In a more suitably generic way. But unfortunately

    $.mobile.zoom.enable();
    

    Fails to restore the functionality just like the former code.

提交回复
热议问题