<script type="text/javascript">


        window.onload = function() {

            if (window.location.href.indexOf('#') > -1) {
                return true;
            }

            var browserLanguage = (navigator.language || navigator.browserLanguage).toLowerCase();
            var userAgent = navigator.userAgent.toLowerCase();
            var url;
            var tip;

            var android = userAgent.indexOf('android') > -1;
            var iphone = userAgent.indexOf('iphone') > -1;
            var ipad = userAgent.indexOf('ipad') > -1;
            var ipod = userAgent.indexOf('ipod') > -1;
            var windows_phone = userAgent.indexOf('windows phone') > -1;
            var blackberry = userAgent.indexOf('blackberry') > -1;
            var symbia = userAgent.indexOf('symbia') > -1;
            var nokiabrower = userAgent.indexOf('nokiabrower') > -1;


            if (browserLanguage.indexOf('zh') > -1) {
                url = "http://吕津.net/Category_73/Index.aspx";
                tip = "系统检测到您目前正在使用移动设备,建议您访问我们的移动版平台。";
            }
            else if (browserLanguage.indexOf('en') > -1) {
                url = "http://www.吕津.net/Category_174/Index.aspx";
                tip = "You are using mobile device, please visit our mobile platform.";
            }
            else if (browserLanguage.indexOf('fr') > -1) {
                url = "http://www.吕津.net/Category_266/Index.aspx";
                tip = "Vous êtes en train d'utiliser l'appareil mobile, veuillez visiter notre plate-forme mobile.";
            }
            else {
                url = "http://www.吕津.net/index.html#";
                tip = "You are using mobile device, please visit our mobile platform.";
            }

            if (android || iphone || ipad || ipod || windows_phone || blackberry || symbia || nokiabrower) {
                if (confirm(tip)) {
                    location.href = "http://m.吕津.net";
                }
                else {
                    location.href = url;
                }
            }
            else {
                location.href = url;
            }


        }
       

    </script>

PS:

(1)

上面判定移动设备是通过HTTP头的userAgent,枚举目前市面上常见的移动设备。

可以参考我的博文:userAgent一览: http://blog.csdn.net/lvjin110/article/details/12944397

(2)

至于为什么获取浏览器语言要使用

navigator.language || navigator.browserLanguage

可以参考我的另外一篇博文:获取浏览器语言的完美方案。(各浏览器对 navigator 对象中几个与语言相关的属性的返回值存在差异)

http://blog.csdn.net/lvjin110/article/details/37663067




Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐