zoukankan      html  css  js  c++  java
  • 移动端版本兼容js

    移动端版本兼容js

    <!--移动端版本兼容 -->

    <script type="text/javascript">
            var phoneWidth = parseInt(window.screen.width);
            var phoneScale = phoneWidth/640;
    
            var ua = navigator.userAgent;
            if (/Android (d+.d+)/.test(ua)){
                var version = parseFloat(RegExp.$1);
                // andriod 2.3
                if(version>2.3){
                    document.write('<meta name="viewport" content="width=640, minimum-scale = '+phoneScale+', maximum-scale = '+phoneScale+', target-densitydpi=device-dpi">');
                // andriod 2.3以上
                }else{
                    document.write('<meta name="viewport" content="width=640, target-densitydpi=device-dpi">');
                }
                // 其他系统
            } else {
                document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">');
            }
            
            if(IsPC()){
                document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">');
            }
    
            function IsPC() {  
               var userAgentInfo = navigator.userAgent;  
               var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");  
               var flag = true;  
               for (var v = 0; v < Agents.length; v++) {  
                   if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }  
               }  
               return flag;  
            }              
    </script>
    转载请注明出处: 欢迎留言或qq(1090413588)交流
  • 相关阅读:
    [LeetCode] Maximum Depth of Binary Tree
    C++11中常用的几个简写
    [LeetCode] Word Break
    [LeetCode] Linked List Cycle II
    sizeof
    string和整形数据之间的转换
    ASCII
    [LeetCode] Linked List Cycle
    机器学习总结-线性回归
    推荐系统初探
  • 原文地址:https://www.cnblogs.com/linyusong/p/5770323.html
Copyright © 2011-2022 走看看