javascript - Script For Assigning Viewport Meta Parameters, iPhone / iPad Conundrum -
i using javascript snippet set content parameters of viewport meta tag, based on width of browser window. script should: sets initial scale value large screen device 1, ipad in portrait mode 0.5, , devices smaller 700px in screen width, 1. however, seems ignore value assigned ipad in landscape mode: 0.75. suspect somehow incorrectly conditional width in landscape mode. i'm using (width <1100 && width >= 900) (to count ipad's 1024px resolution , provide levee other devices of similar screen sizes) - but on ipad in landscape mode instead shrinks page 0.5 (applying next conditional).
question: modifications necessary make work ipad in landscape mode?
here's snippet:
<script type="text/javascript"> var width = screen.width; var meta = document.createelement("meta"); var head = document.getelementsbytagname("head")[0]; if (width >= 1100) { meta.setattribute("name", "viewport"); meta.setattribute("content", "width=device-width, initial-scale=1"); head.appendchild(meta); } else if (width < 1100 && width >= 900) { // ipad in landscape mode meta.setattribute("name", "viewport"); meta.setattribute("content", "width=device-width, initial-scale=0.75"); head.appendchild(meta); } else if (width < 900 && width >= 700) { // ipad in portrait mode meta.setattribute("name", "viewport"); meta.setattribute("content", "width=device-width, initial-scale=0.5"); head.appendchild(meta); } else if (width <700) { // smaller 700px in width meta.setattribute("name", "viewport"); meta.setattribute("content", "width=device-width; initial-scale=1; maximum-scale=1"); head.appendchild(meta); }; </script>
Comments
Post a Comment