Skip to content

Instantly share code, notes, and snippets.

@ckhatton
Created December 9, 2014 20:33
Show Gist options
  • Save ckhatton/561581d017b3c5668921 to your computer and use it in GitHub Desktop.
Save ckhatton/561581d017b3c5668921 to your computer and use it in GitHub Desktop.
Sets the viewport depending on the device.
<meta id="viewport" name='viewport'>
<script>
(function(doc) {
var viewport = document.getElementById('viewport');
if ( navigator.userAgent.match(/iPhone|iPod/i) || screen.width <= 640) {
doc.getElementById("viewport").setAttribute("content", "initial-scale=0.3, maximum-scale=1.0, width=device-width");
} else if ( navigator.userAgent.match(/Android|webOS|iPad|BlackBerry|IEMobile|Opera Mini/i) || screen.width > 640 ) {
doc.getElementById("viewport").setAttribute("content", "initial-scale=1.0, maximum-scale=1.0, width=device-width");
}
}(document));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment