Skip to content

Instantly share code, notes, and snippets.

@bergantine
Created January 3, 2014 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bergantine/8233006 to your computer and use it in GitHub Desktop.
Save bergantine/8233006 to your computer and use it in GitHub Desktop.
Fix iPhone (iOS) Safari viewport scaling bug when rotating between landscape and portrait (from http://webdesignerwall.com/tutorials/iphone-safari-viewport-scaling-bug)
<script type="text/javascript">
(function(doc) {
var addEvent = 'addEventListener',
type = 'gesturestart',
qsa = 'querySelectorAll',
scales = [1, 1],
meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
function fix() {
meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
doc.removeEventListener(type, fix, true);
}
if ((meta = meta[meta.length - 1]) && addEvent in doc) {
fix();
scales = [.25, 1.6];
doc[addEvent](type, fix, true);
}
}(document));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment