I have spent all day looking for a solution, and this site keeps coming up, SO why not ask you guys.
I an building our companies mobile website and we want to disable the auto zoom mobile devices use to zoom into text/search/email inputs when they are focused on.
I am building the site in HTML5 and have seen/tested the
<meta name="viewport" content="width=device-width, user-scalable=no" />
solution. With various properties (ie. minimum-scale=#, maximum-scale=#" )
This, works in almost ALL mobile devices I am testing on. Only one problem. I want the user to be able to zoom in/out at their leisure. (we have some higher res product shots that would be nice to see up close)
How can I disable zooming in when clicking on input tags, while retaining full manual user zoom control?
p.s the site also uses jQuery. So any thoughts using that might help.
thank you
Jrak
Setting the meta tag in the <head>
like this worked for me:
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
It may not work exactly for your styling, but if you set the font-size of input elements to be 16px or above, the onfocus zooming will stop.
See: Disable Auto Zoom in Input "Text" tag - Safari on iPhone
There's no clean way I could find, but here's a hack...
1) I noticed that the mouseover event happens prior to the zoom, but the zoom happens before mousedown or focus events.
2) You can dynamically change the META viewport tag using javascript (see Enable/disable zoom on iPhone safari with Javascript?)
So, try this (shown in jquery for compactness):
$("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" />');
}
This is definitely a hack... there may be situations where mouseover/down don't always catch entries/exits, but it worked well in my tests and is a solid start.
It took me a while to find it but here's the best code that I found......http://nerd.vasilis.nl/prevent-ios-from-zooming-onfocus/
var $viewportMeta = $('meta[name="viewport"]');
$('input, select, textarea').bind('focus blur', function(event) {
$viewportMeta.attr('content', 'width=device-width,initial-scale=1,maximum-scale=' + (event.type == 'blur' ? 10 : 1));
});
a very simple hack is to set:
input, textarea {font-size:16px;}
If you set a webkit transform to any value other than 1 (or 1.0)
then auto-zoom on selecting an input tag is disabled on iPhone.
document.body.style.webkitTransformOrigin= "0% 0%";
document.body.style.webkitTransform = "scale(1.1)";
I haven't tested other mobile browsers.