判断pc浏览器和手机浏览器方法

//平台、设备和操作系统
        var system = {
            win: false,
            mac: false,
            xll: false,
            ipad:false
        };
        //检测平台
        var p = navigator.platform;
        system.win = p.indexOf("Win") == 0;
        system.mac = p.indexOf("Mac") == 0;
        system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
        system.ipad = (navigator.userAgent.match(/iPad/i) != null)?true:false;
        //跳转语句,如果是手机访问就自动跳转到wap.baidu.com页面
        if (system.win || system.mac || system.xll||system.ipad) {  
            
        } else {
            window.location.href = "http://www.baidu.com";
        }

        //平台、设备和操作系统
        var system = {
            win: false,
            mac: false,
            xll: false,
            ipad:false
        };
        //检测平台
        var p = navigator.platform;
        system.win = p.indexOf("Win") == 0;
        system.mac = p.indexOf("Mac") == 0;
        system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
        system.ipad = (navigator.userAgent.match(/iPad/i) != null)?true:false;
       
        if (system.win || system.mac || system.xll||system.ipad) {  
           
        } else {
            var weixin =new is_weixn;
        }
        function is_weixn(){
            var ua = navigator.userAgent.toLowerCase();
            if(ua.match(/MicroMessenger/i)=="micromessenger") {
                return true;
            } else {
                jQuery(document).ready(function($){
                   login();
                })
            }
        }
        function login(){
            var obj = new WxLogin({
                id: "code",
                appid: appid,
                scope: "snsapi_login",
                redirect_uri: "http%3a%2f%2fwww.caiex.com%2fCAIEX-GAME%2floginController%2floginFallsGame.shtml%3fpageName%3d55",
                state: randomString(6),
                style: "black",
                href: ""
            });
            $('.theme-popover-mask').fadeIn(100);
            $('.theme-popover').slideDown(200);
        }

原文地址:https://www.cnblogs.com/happiness-mumu/p/6023245.html