二维码根据设备显示

javascript

2014-12-30 13:06

<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>手机APP下载页面</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">

    <script type="text/javascript">
 
 
 function is_weixn(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}


 if (!is_weixn()){
 
        // 获取终端的相关信息
        var Terminal = {
            // 辨别移动终端类型
            platform : function(){
                var u = navigator.userAgent, app = navigator.appVersion;
                return {
                    // android终端或者uc浏览器
                    android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
                    // 是否为iPhone或者QQHD浏览器
                    iPhone: u.indexOf('iPhone') > -1 ,
                    // 是否iPad
                    iPad: u.indexOf('iPad') > -1
                };
            }(),

            language : (navigator.browserLanguage || navigator.language).toLowerCase()
        }
  
        // 根据不同的终端,跳转到不同的地址
        var theUrl = 'http://www.0.com';
        var apps='https://itunes.apple.com/cn/app/itunes-u/id490217893?mt=8';
        if(Terminal.platform.android){
            theUrl = 'http://www.0.cn/yg.apk';
        }else if(Terminal.platform.iPhone){
            theUrl = apps;

        }else if(Terminal.platform.iPad){
            // 还可以通过language,区分开多国语言版
            switch(Terminal.language){
                case 'en-us':
                    theUrl = apps;
                    break;
                case 'ko-kr':
                    theUrl = apps;
                    break;
                case 'ja-jp':
                    theUrl = apps;
                    break;
                default:
                    theUrl = apps;
            }
        }
   
        location.href = theUrl;
 }
    </script>
</head>
<body>
  
       直接进入<a href=http://www.0cn/>触屏版</a>
 
</body>
</html>