80

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 don't want it to zoom in - sounds easy, right?

Here's where it gets fun: I have to be able to zoom in general so don't say

<meta name='viewport' content='user-scalable=0'>

That won't work for me.

Also, the input box doesn't receive click events. It appears when another button is clicked a gets focus programmatically.

Here's what I've tried and they've failed so far:

jQuery('head meta[name=viewport]').remove();
jQuery('head').prepend('<meta name="viewport" content="width=720px;intial-scale=1.0;maximum-scale=1.0;user-scalable=no" />');
jQuery("#locationLock input").focus();
jQuery('head meta[name=viewport]').remove();
jQuery('head').prepend('<meta name="viewport" content="width=720px;intial-scale=1.0;maximum-scale=1.0;user-scalable=yes" />');

This also failed:

<input type='text' onfocus="return false">

And this:

jQuery("#locationLock input").focus(function(e){e.preventDefault();});

Any ideas?

Matt
  • 70,063
  • 26
  • 142
  • 172
Coomie
  • 4,540
  • 3
  • 29
  • 44
  • So the Chrome Browser only zooms when there's content already in the input field, so you could try perfecting removing the content, setting a timeout, then adding the content back later, around (150ms). Still there's a few issues with the first long-pressed focus on an input field. IMO if you want to do this, keep the timeout short, add a little jQuery loading effect for UX reasons and fallback to simply having a 18px font size for the input The zoom is there so the user can more easily change the caret position, so think about this too. – niall.campbell May 25 '14 at 00:31
  • 1
    Star the issue here: https://code.google.com/p/chromium/issues/detail?id=181560 – Jo P Sep 01 '14 at 16:41
  • **Moderator Note**: Over time, this question has accrued over 30 answers. Before adding a new answer, be **sure** that your solution has not already been provided. – Matt Aug 07 '15 at 11:39

37 Answers37

38

The following worked for me (Android Galaxy S2):

<meta name="viewport" content="width=device-width, height=device-height,  initial-scale=1.0, user-scalable=no;user-scalable=0;"/>
rebpp
  • 417
  • 4
  • 3
  • This should definitely be the current correct answer! – axelbrz Feb 27 '15 at 01:09
  • 3
    This works. However you should use , instead of ; I also guess the comment about usability may be ignored as we are probably all here because of a bad usability experience in a certain case, where we explicitly want to prevent that behavior. – Jey DWork Apr 14 '15 at 22:05
  • Works on iPhone X. This should be the correct answer – Shalin Nipuna Apr 24 '20 at 10:44
30

Not possible!

I've got some bad news for you all. It's now been 6 months and no one has correctly answered the question.

Also I've finished working on that project and employer.

I'm afraid to say it, but exactly what I asked for is impossible. Sorry peoples. But I'm going to leave the question alive so people can see the other options.

Coomie
  • 4,540
  • 3
  • 29
  • 44
  • 7
    Any solution a year later? – Justin Cloud Jan 04 '14 at 02:12
  • 1
    Add a Star to the Chromium issue report here to get this noticed by Google: https://code.google.com/p/chromium/issues/detail?id=181560 – Jo P Sep 01 '14 at 16:40
  • 1
    There are plenty of solutions, the best is to ensure that your document body is not wider than the native screen size. – Tony Chiboucas Oct 01 '14 at 23:56
  • 1
    It is now official : this annoying feature is now finally removed in new version of Chrome! See https://code.google.com/p/chromium/issues/detail?id=181560#c28 and https://codereview.chromium.org/196133011/ . – Med Feb 19 '15 at 09:27
  • Actually the biggest problem was not the zooming itself - it's nice to give users a better option to see what they are typing - but the fact that after finishing typing and closing the keyboard the page does not zoom back as it was. So, we just have to hope that everybody on Android 4.1 devices will upgrade their browsers to the latest Chrome... even the ones who still are using default Android Browser. – JustAMartin Dec 06 '17 at 15:51
  • Note that in Android Firefox, the zooming can be disabled in about:config, set formhelper.autozoom = false. – following Nov 19 '19 at 20:42
15

Scale Issues Cause Zoom on Input Focus

There is a great difficulty in sizing the content for different screen resolutions and sizes, which ultimately is the cause of this zoom issue.

Most mobile browsers have a trigger on input focus (that you can't over-ride without difficulty):

if (zoom-level < 1)
   zoom to 1.5
   center focused input relative to screen

*yes, that was way over-simplified.

Myth of meta-tag scale fixes.

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> All such viewport settings will not prevent the input-focus zoom if you are zoomed-out. These will also not over-ride any other html, body, or element sizing that would push the window to width wider than the screen.

Primary Cause

Using a window or body size larger than the device screen dimensions.

Consider the standard screen-size of most of the Galaxy line of Android smartphones: 360 x 650. If your document body, or window, is defined to be larger than that (let's say 1024 wide to make it obvious), a few things may happen:

  1. The browser may auto-zoom out, to fit the width to the screen.
    1. The user may do the above.
    2. You may have done the above.
  2. The browser will restore the zoom-level on subsequent visits to the page.
  3. You're now viewing the content at ~0.35x zoom.

Initial State 1x

When loaded, the page won't fit. Some browsers may zoom-out to fit the window, but the user most certainly will. Additionally, if you zoomed-out on this page once, the browser will store the zoom-level.

Zoom Out to Fit 0.35x

Once zoomed out, the width will fit nicely, and a page with more vertical area will fill out the screen quite nicely... but...

Notice that the browser is now in a state where text and input (sized for normal 1x zoom) would be way too small to read, thus triggers a usability behavior of zooming on the input fields when they get focus.

Zoom on Input-Focus 1.5x

Typical behavior in the above case, is to zoom to 1.5x, to ensure input visibility. The result (if you've styled everything to look better when zoomed-out, or for the larger screen) is less than desirable.

Solution 1

Use a combination of css media rules, device-detection, or whatever best suits your situation. Set the window and body to a size that fills the screen-space, without exceeding it.

  • This is why so many people have success with forcing input text-size to 16px;
    • once you do that, its clear that you're WAY zoomed out.
    • it also has the added benefit of tricking the browser into allowing slightly zoomed out windows to not trigger the focus-zoom.

Solution 2

Use the meta viewport, but then be careful with css widths.

<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  • When using this method, you must do one of the following:
    • Only use percentages for widths.
    • Define an em width, and only use em and % for widths.
    • see Solution 1 for using px widths.

Solution 3

jQuery.mobile $.mobile.zoom.disable();

Just make sure you start developing with it from the start, and not from the middle.

Tony Chiboucas
  • 4,835
  • 24
  • 35
12

I'm not sure if this is the best way but this works for me on android and iphone.

input:focus { font-size: 16px!important}

You can use media queries to target mobile devices only.

Saroj
  • 1,018
  • 11
  • 16
  • ...additionally, this is usually caused by improperly sized/zoomed window/body. – Tony Chiboucas Oct 01 '14 at 23:52
  • You cannot use media queries to target mobile devices only their widths or heights. Many touch devices are as large as desktop devices. Touch or no-touch device detection is scripting or server side. – Christina Oct 15 '14 at 15:50
  • I don't think this is even close to be a correct answer. The problem with auto zoom is not only in terms of "small font", but also an illusion of improperly positioned elements. In my case, for example, the input is being zoomed in and not centered on screen, so I've been reported a "wrong dialog position" when user didn't knew about this "autozoom" – Kamilius Apr 15 '15 at 07:01
4

Yes, it's possible

input[type='text'],input[type='number'],textarea {font-size:16px;}

Tested in Android 4.2 browser and Android Chrome.

https://stackoverflow.com/a/6394497/4264

The only case I found that it kept zooming was in Chrome with Settings -> Accesibility -> Text scaling higher than 100%.

Community
  • 1
  • 1
Santiago Corredoira
  • 40,844
  • 8
  • 48
  • 56
4

Ran into this issue today and may have a chromium update coming down the pipe soon that could resolve it. Per the chromium issue pointed to by @Jo,

no.28 jdd...@chromium.org As of https://codereview.chromium.org/196133011/, autozooming is disabled on sites that have a mobile-optimized viewport (e.g., "width=device-width" or fixed page scale viewport annotation).

There may still be auto-scrolling when focusing editable elements on such sites, to maintain the element's visibility, but zooming will be disabled. This will go live in M41 (still a good number of weeks from hitting beta channel).

We don't have any plans to otherwise prevent autozooming for legacy desktop sites.

As of this time, Chrome is v.40; v.41 is in BETA. Will be checking in to see if focus continues to be lost on the Android Chrome browser.

Community
  • 1
  • 1
cthorpe
  • 96
  • 1
  • 3
  • Fixed the my instance of this occurrence. For me, this bug came across while moving elements (including a form w/ two text inputs) for media-queries. Using jQuery's .insertBefore() / .insertAfter() broke down something and using .prependTo() / .appendTo() worked. That is, it didn't force Android Chrome to resize on input focus. – cthorpe Feb 05 '15 at 16:19
3

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.

  • preventFocusZoom causes havoc with the Android native browser. Each time a form input is focused, the page scrolls to the top, the input does not receive focus and the keyboard is not displayed until you try to focus the input a second time. Reported as bug. – Billy Oct 18 '14 at 05:43
3
font-size: 18px;

This fixed it for my Nexus 7 (2011) running Android 4.3.

This problem only exists for me on the Nexus 7, the following devices all appear happy with font-size: 16px:

  • HTC Desire Android 2.3.7
  • Nexus 4 Android 4.3

Hope this helps someone!

Hung-Su
  • 39
  • 2
  • Recently tested on Nexus4. Found that 18px is not enough. I'm using points, so I ended up using 1.3em – wormhit Jan 20 '14 at 10:23
  • Thanks wormhit. I've found that lately my Nexus 7 no longer has zoom issues, which may be a result of Android 4.4. – Hung-Su Mar 03 '14 at 13:46
  • Setting font size to 18px also did the trick for Galaxy Note 3. – Lev Aug 18 '14 at 08:27
  • Forcing the content to a specific font-size is not an acceptable solution, as 16px or 18px on an HD res screen, will be less than readable unless you also force a degree of zoom with css. That would make this a very bad css hack which would NOT work well on other systems – Tony Chiboucas Oct 01 '14 at 19:26
  • @TonyChiboucas but CSS `px` are [not device pixels](http://www.howdesign.com/featured/hardware-css-pixels-retina-display/) – z0r Jun 17 '16 at 08:47
2

This works where #inputbox is the id of the input form element.

I'm using this to stop a search box from auto zooming in IOS it's a mod of the earlier post above since the mouseover event would only work the first time but fails to trigger subsequent times. Enjoy this it was a real hair puller...

$("#inputbox").live('touchstart', function(e){
    $('head meta[name=viewport]').remove();
    $('head').prepend('<meta name="viewport" content="user-scalable=0" />');
    }
);

$("#inputbox").mousedown(zoomEnable);

function zoomEnable(){
  $('head meta[name=viewport]').remove();
  $('head').prepend('<meta name="viewport" content="user-scalable=1" />');
}
Stephan
  • 37,597
  • 55
  • 216
  • 310
Dotnoise
  • 21
  • 1
2

Just a side note:

The solution with the meta name="viewport" works perfectly. However, both native and Chrome browsers in Android have an accessibility setting named "Override website's request to control zoom". If this setting is set, nothing in HTML, CSS, or JavaScript can disable zooming.

Serge
  • 621
  • 7
  • 6
2

You need 2 things:

Use a metatag like this in your head to avoid the user from zooming:

<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />

And then in your css put something like the following to avoid the browser from zooming:

* { font-size:16px; }

Done! I think the browser resizes your viewport based on the smallest font or something like that. Maybe someone could explain it better, but it worked :)

Beto Aveiga
  • 2,931
  • 3
  • 23
  • 34
  • For testing I wrote in my css * { font-size:16px !important; } and the zoom has gone completely. I think that some texts in the page that remain small cause the browser to zoom when focusing an input. – Beto Aveiga Mar 20 '15 at 23:42
  • Right now my page is too complex in the html structure. It would be nice to test with a simplier markup to find a better solution. – Beto Aveiga Mar 20 '15 at 23:46
1

Working Model

We have this working on Android. Here is the key: the font-size on the input must be the proper size. If you're page is 320px wide then you need 16px font size. If you're size is 640px then you need 32px font size.

In addition you need the following

320 wide version

<meta name="viewport" content="width=320, initial-scale=1, maximum-scale=1, minimum-scale=1" />

640 wide version

<meta name="viewport" content="width=640, initial-scale=.5, maximum-scale=.5, minimum-scale=.5" />

NOTE: THIS DOES NOT CONTAIN THE USER SCALABLE ATTRIBUTE. THAT WILL BREAK IT.

Soshmo
  • 270
  • 2
  • 7
1

For anyone that is trying to stop zoom when trying to focus on a hidden input field, you can make the hidden input as big (or at least as wide) as the screen area(or viewable area) - this stopped it zooming.

e.g.

HIDDENinput.style.width = window.innerWidth;

HIDDENinput.style.height = window.innerHeight; (optional)

Aaron
  • 204
  • 1
  • 6
1

This may be good answer:

input, textarea {
  max-width:100%;
}

Don't use <meta name=viewport content='user-scalable=no'>

Guru
  • 370
  • 1
  • 5
  • 15
1

I'm not sure if you can disable the zoom, but you can set a restriction like this

 <meta id="viewport" name="viewport" content="width=device-width,initial-scale=0.5,maximum-scale=0.5,minimum-scale=0.5,user-scalable=no">

maximum-scale=0.5 and minimum-scale=0.5 should do the trick. It worked for me.

Razvan Tanase
  • 99
  • 1
  • 7
1

Typically you don't want to disable the accessibility features.

But you can get around the zoom issue by simply adding a fixed div and placing your web page inside it.

#app {
  position: fixed;
  top: 0em;
  bottom: 0em;
  left: 0em;
  right: 0em;
  overflow: scroll;
 }
<body>
<div class="app">
  <!-- the rest of your web page  -->
  <input type="text">
</div>
</body>
<body>
     <div class="app">
     </div>
</body>
1

add this meta tag to your html file and it will solve the issue.

<html><head><meta name='viewport' content='width=device-width, initial-scale=1.0, user-scalable=0' ></head><body>html code</body></html> 
Patel Disha
  • 169
  • 1
  • 4
1

If you set font size of input to 16px the zoom stops. Mobile browsers assume anything less than 16px means the users will need to zoom so why don't i do it myself.

 input[type='text'],input[type='number'],textarea {font-size:16px;}
 body{ -webkit-text-size-adjust:none;}

You may also set the below meta tag but it prevent user scaling completely.

<meta name="viewport" content="width=device-width,  initial-scale=1.0, user-scalable=0;"/>

If you want user scaling but only disable input scaling try this

$("input[type=text], textarea").mouseover(zoomDisable).mousedown(zoomEnable);
function zoomDisable(){
  $('head meta[name=viewport]').remove();
  $('head').prepend('<meta name="viewport" content="user-scalable=0" />');
}
function zoomEnable(){
  $('head meta[name=viewport]').remove();
  $('head').prepend('<meta name="viewport" content="user-scalable=1" />');
}

also try this

aWebDeveloper
  • 31,131
  • 35
  • 150
  • 224
  • 1
    @tobyodavies My Android (HTC Desire S) actually handles changes to the `viewport` meta tag. I'm resetting zoom like so: `$('meta[name=viewport]').attr('content', 'initial-scale=1.0, maximum-scale=0.05');` however this causes the browser to move the viewport to left,top = 0,0. – KajMagnus May 22 '12 at 12:57
0

Perhaps you could avoid zoom, by resetting the zoom scale to 1.0? On my Android (HTC Wildfire S), I'm able to reset zoom to 1.0 like so:

$('meta[name=viewport]').attr('content',
         'initial-scale=1.0, maximum-scale=0.05');

but this moves the viewport to 0, 0 (the upper left corner of the page). So I $().scrollLeft(...) and .scrollTop(...) back to the form again.

(initial-scale=1.0, maximum-scale=0.05 is my initial value of the viewport meta.)

(The reason I do this is not to prevent Android from zooming, but rather to reset the zoom to a known scale, because of other Android bugs that otherwise corrupt screen.width and other related values.)

KajMagnus
  • 10,177
  • 14
  • 69
  • 115
0

Try this one, it works on my device:

<meta content="minimum-scale=1.0, width=device-width, maximum-scale=1.0, user-scalable=no" name="viewport" /> 

However, when I double click over the input box, the keyboard slides up and makes the page lessen in height.

nhahtdh
  • 52,949
  • 15
  • 113
  • 149
Shi Chuan
  • 19
  • 1
0

By accident I discovered that this:

 input {
     line-height:40px;
 }   

will prevent zoom on input on my Galaxy Nexus with Chrome for Android version 18 although that might be specific to my case:

<meta name='viewport' data='width=800'>

so for future reference, if you come here via google, this may be one of other solutions.

t0mm13b
  • 32,846
  • 7
  • 71
  • 106
aep
  • 736
  • 5
  • 26
0

I had the same problem (only in Android chrome browser). I solved the issue like this.

  1. Detected the userAgent, and bind the onFocus and onBlur events of the text fields to change the viewport meta content as follows

    if ((navigator.userAgent.match(/Android/i)) && (navigator.userAgent.toLowerCase().indexOf('chrome') > -1)) {
    isAndroidChrome = true;    
    }
    var viewportmeta = document.querySelector('meta[name="viewport"]');
    
  2. onFocus of the text field, I set the following viewport meta content viewportmeta.content = 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1';

  3. onBlur of the text field, I am resetting the viewport meta content to viewportmeta.content = 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1.4'; you can set the maximum-scale if you wish, or if you want it to be user-scalable, don't set maximum-scale

When you change the trigger the onFocus event of the input, if the maximum-scale is 1, it doesn't zoom in. This worked for me like a charm. Hope it works for you too.

Vignesh PT
  • 616
  • 11
  • 27
0

As @soshmo said, user-scalable isn't an attribute that WebKit likes and so its inclusion causes WebKit to discard the whole viewport tag. I also found this to be the case with setting maximum-scale to anything other than 1, and that didn't stop the zooming.

Resetting the viewport on every focus and blur event worked for me:

var htmlWidth = parseInt($('html').outerWidth());
var screenDPI = parseInt(window.devicePixelRatio);
var screenWidth = parseInt(screen.width);
var screenHeight = parseInt(screen.height);    
var scaleVal = (((screenWidth * screenDPI) / htmlWidth)/screenDPI);
$('input[type="text"], input[type="password"], input[type="email"]').each(function() {

    //unchained for clarity

    $(this).focus(function() { 
        $('meta[name="viewport"]').attr('content', "initial-scale=' + scaleVal + ', maximum-scale=1, minimum-scale=' + (scaleVal) + ', width=device-width, height=device-height");
        // Do something to manage scrolling the view (resetting the viewport also resets the scroll)
        $('html, body').scrollTop(($(this).offset().top - (screenHeight/3)));
    });

    $(this).blur(function() { 
        $('meta[name="viewport"]').attr('content', "initial-scale=' + scaleVal + ', maximum-scale=1, minimum-scale=' + (scaleVal) + ', width=device-width, height=device-height");
    });
});

If you find that setting/resetting the viewport it's worth checking that WebKit accepts the content attributes that you're using. It took me a while to realise that using things like user-scalable caused the viewport to be discarded, so even though the JavaScript was working, the changes were not affected.

0

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);
Gergo Erdosi
  • 36,694
  • 21
  • 106
  • 90
0

For Nexus 7 I was getting this issue when my media query was -

@media screen and (max-device-width: 600px) and (orientation : portrait)

So I used below media query to resolve the issue -

@media screen and (max-device-width: 600px) and (max-aspect-ratio: 13/9)

sam
  • 1
0

Bit late to the party, but I spent a whole afternoon yesterday going nuts before I got to this post and realized it was a feature/bug from Android. So I'll post my solution. This worked for me, and still enables user zoom:

Meta:

<meta id="meta1" name="viewport" content="width=device-width,initial-scale=1,minimal-ui"/>

CSS:

html{
    position:absolute;
    overflow:-moz-scrollbars-vertical;
    overflow-y:scroll;
    overflow-x:hidden;
    margin:0;padding:0;border:0;
    width:100%;
    height:100%;
    }
body{
    position: relative;
    width: 100%;
    height: 100%;
    min-height:100%;
    margin: 0;
    padding: 0;
    border: 0;
}

Setting HTML to position:absolute and overflow-x:hidden did the trick for me.

Michel
  • 3,592
  • 4
  • 33
  • 46
0

Worked for galaxy 4 :
Add the code to HTML header index file :

<meta name="viewport" content="width=device-width, height=device-height,  initial-scale=1.0, user-scalable=no;user-scalable=0;"/>
shay golan
  • 21
  • 4
0

I post a answer because I faced a similar problem and I resolved it.

My condition is below.

A viewport setting in html head is

<meta name="viewport" content="width=640">

Agents are Android default browser.
They aren't Chrome, Firefox and Safari.
Android versions are under 4.2.x.

Details of our situations are not same but I think they have an essentially equal problem.

I resolved it to add "target-densitydpi=device-dpi" into meta[name=viewport] tag.

<meta name="viewport" content="width=640, target-densitydpi=device-dpi">

Try it please.

But I have to say that "target-densitydpi=device-dpi" would have a side effect.

Bad case is here.

  1. An android OLD browser reads "target-densitydpi=device-dpi".
  2. It goes to the other page which has no target-densitydpi property.
  3. The browser starts to render the page as "target-densitydpi=device-dpi".
  4. So it renders the next page in a wrong scale factor.

A solution of this case is to rewrite target-densitydpi property to "medium-dpi" from "device-dpi" using javascript before going to the next page.

An example using jQuery.

<a href="go-to-the-other" class="resetDensityDpi">Other page</a>
<script>
$(function(){
    $('.resetDensityDpi').click(function(){
        var $meta = $('meta[name="viewport"]');
        $meta.attr('content', $meta.attr('content').replace(/target-densitydpi=device-dpi/, 'target-densitydpi=medium-dpi'));
        return true;
    });
});
</script>

And... this code causes a new problem.
Some browsers render results of javascript process using cache data when they go back to previous page using a back button. So they display the previous page as "target-densitydpi=medium-dpi" NOT as "target-densitydpi=device-dpi".

A solution of this is just the opposite of above.

<script>
$(function(){
    var rollbackDensityDpi = function() {
        // disable back-forword-cache (bfcache)
        window.onunload = function(){};

        var $meta = $('meta[name="viewport"]');
        if ($meta.attr('content').match(/target-densitydpi=medium-dpi/)) {
            $meta.attr('content', $meta.attr('content').replace(/target-densitydpi=medium-dpi/, 'target-densitydpi=device-dpi'));
        }
    };

    if (window.addEventListener) {
        window.addEventListener("load", rollbackDensityDpi, false);
    } else if (window.attachEvent) {
        window.attachEvent("onload", rollbackDensityDpi);
    } else {
        window.onload = rollbackDensityDpi;
    }
});
</script>

Thank you.

0

Keep the content narrower than the window.

You will have to design your page from the beginning with this in mind, but it is entirely effective.

The key is to use the @media css at-rule to only allow components to have widths that you know the screen is big enough to contain.

For example, if you have a content width set so that the text doesn't get too spread out on a larger monitor, make sure that width only applies to large screens:

@media (min-width: 960px){
.content{
  width : 960px;
}
}

Or maybe you have an image that is 500px wide, you might have to hide it on smaller screens:

@media (max-width: 500px){
.image{
  display : none; 
}
}
Community
  • 1
  • 1
martin
  • 962
  • 2
  • 11
  • 19
-1

add this meta tag to your html file and it will solve the issue.

<meta name="viewport" content="width=device-width, user-scalable=no" />

adding this line solved issue for me in HTC desire 816 and SAMSUNG GALAXY S5.

AJay
  • 1
  • 3
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – Rajesh Loganathan Nov 17 '14 at 11:53
  • check the answer now SVMRAJESH it will solve coz it has solved for me – AJay Nov 17 '14 at 12:12
  • Please check timing. I mentioned 2 hours ago. But after seen my comment only your added code here. If its solves problem then ok. But don't give simply text as like past. – Rajesh Loganathan Nov 17 '14 at 13:56
  • Cool buddy. No issues – Rajesh Loganathan Nov 18 '14 at 05:46
-1

Try using this, this will fit into device size and avoid zoom in/out

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
Thofiq
  • 1
  • 1
-1

From what I tried the best thing that worked is to make the font inside the input 16px or more. Definitely works on the last version on chrome.

-2

This may be a solution to that kind of probleme

<meta name="viewport" content="user-scale=no"/>
<meta name="viewport" content="width=device-width"/>
<meta name="viewport" content="width=device-width, maximum-scale=0.9"/>
Ir Calif
  • 428
  • 5
  • 6
-3

This works great for me.

input[type='text'],input[type='number'],textarea {font-size:16px; !important}
Austin Lovell
  • 1,039
  • 3
  • 15
  • 29
  • Forcing the content to a specific font-size is not an acceptable solution, as 16px on an HD res screen, will be less than readable unless you also force a degree of zoom with css. That would make this a very bad css hack which would NOT work well on other systems. – Tony Chiboucas Oct 01 '14 at 19:26
  • ...additionally, this is usually caused by improperly sized/zoomed window/body. – Tony Chiboucas Oct 01 '14 at 23:53
-3

SOLUTION FOUND!!!!!!!!!!!!!!!

At least for people that works with Phonegap/Cordova

I'm using a Galaxy Tab pc1010 with Android Froyo (2.2) I'm using Cordova 2.4.0

Add these beautiful lines to your HTML head element:

<meta name="viewport" content="user-scale=no"/>
<meta name="viewport" content="width=device-width"/>
<meta name="viewport" content="width=device-width, maximum-scale=0.9"/>

Type them separately and use maximum scale of 0.9. I was having this problem when selecting an input field that my layout disadjusted just a little bit from the top and from the left, tried to repair it using javascript element style modification but it was awful. Thank God I found this configuration in an old mobile site project created using some tutorials with this trick.

Nick Dickinson-Wilde
  • 977
  • 2
  • 13
  • 20
-3

My advice would be to take a look at the best practices for android web development. To be more specific, you may need to include more in your meta tag to prevent the zooming from occurring. For Example:

<!-- set the screen width to the device width -->
<!-- set the viewport to be non-zoomable -->
<!-- fix the initial zoom to be 1:1 -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
NT3RP
  • 14,302
  • 9
  • 56
  • 96
  • 7
    This doesn't answer the question... I said I need to be able to scale, I just want to prevent zoom on input boxes... This code still zooms in on input boxes and prevents zooming so I can't zoom out. – Coomie Aug 29 '11 at 04:05
  • 4
    This answer is not even close. – Rick Kukiela Nov 03 '11 at 06:09
-6

Incase anyone was wondering you can actually get around this whole input box zooming (certainly on an iTouch as it's all I have to test on) by making the input readonly.

$("#your-input").focus(function(event){
event.preventDefault();
$(this).prop({ readOnly: true });
/*
Do your magic

*/
$(this).prop({readOnly:false});
});

I was really surprised to find nobody had yet tried this!

alex
  • 438,662
  • 188
  • 837
  • 957
Nodex
  • 5
  • 1