移动端游览器自适应调整
1 <script type="text/javascript">// <![CDATA[ 2 var jsVer = 28; 3 4 var phoneWidth = parseInt(window.screen.width); 5 6 var phoneScale = phoneWidth / 640; 7 8 var ua = navigator.userAgent; 9 10 if (/Android (d+.d+)/.test(ua)) { 11 12 var version = parseFloat(RegExp.$1); 13 14 // andriod 2.3 15 16 if (version > 2.3) { 17 18 document.write('<meta name="viewport" content="width=640, minimum-scale = ' + phoneScale + ', maximum-scale = ' + phoneScale + ', target-densitydpi=device-dpi">'); 19 20 // andriod 2.3以上 21 22 } else { 23 24 document.write('<meta name="viewport" content="width=640, target-densitydpi=device-dpi">'); 25 26 } 27 28 // 其他系统 29 30 } else { 31 32 document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">'); 33 34 } 35 // ]]></script>