Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created April 5, 2011 05:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save paulirish/2add4e06a1cebff2def0 to your computer and use it in GitHub Desktop.
Save paulirish/2add4e06a1cebff2def0 to your computer and use it in GitHub Desktop.
// http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
// http://adactio.com/journal/4470/
var viewportmeta = document.querySelector && document.querySelector('meta[name="viewport"]'),
ua = navigator.userAgent,
gestureStart = function () {
viewportmeta.content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
},
scaleFix = function () {
if (viewportmeta && /iPhone|iPad/.test(ua) && !/Opera Mini/.test(ua)) {
viewportmeta.content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
document.addEventListener("gesturestart", gestureStart, false);
}
};
scaleFix();
@mathiasbynens
Copy link

I purposefully didn’t test for document.querySelector support in my gist, but if you’re gonna do so then why not use:

var viewportmeta = document.querySelector && typeof document.querySelector == 'function' && document.querySelector('meta[name="viewport"]');

Or would that be overkill?

@paulirish
Copy link
Author

Oh your gist is Sweet!

yay.

sry i didnt see it linked up anywhere. toss a link on shichuan's post!

also checking that querySelector is both truthy AND a function is overkill yes. :)

@mathiasbynens
Copy link

Check out @jdalton’s fork, it’s super hawt: https://gist.github.com/903131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment