Disable zoom on input focus in Android webpage

后端 未结 30 1212
日久生厌
日久生厌 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:19

    Setting the viewport user-scalable property on touchstart did it for me, no need to remove then re-add simply change it on touchstart then enable again on blur. Means the user can't zoom whilst focused on the field but a small price to pay I think.

    var zoomEnable;
    
    zoomEnable = function() {
      $("head meta[name=viewport]").prop("content", "width=device-width, initial-scale=1.0, user-scalable=yes");
    };
    
    $("input[type='text']").on("touchstart", function(e) {
      $("head meta[name=viewport]").prop("content", "width=device-width, initial-scale=1.0, user-scalable=no");
    });
    
    $("input[type='text']").blur(zoomEnable);
    

提交回复
热议问题