判断是否为移动端运行环境

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>判断是否为移动端运行环境</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
</head>
<body>
<script>
    // 判断是否为移动端运行环境
var mob = '';
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){ 
    if(window.location.href.indexOf("?mobile")<0){ 
        try{ 
            mob = 'true'; 
        } 
        catch(e){} 
    } 
}else{ 
    mob = 'false';
};

    /*使用*/
    if(mob=='true') {
        $('.courseOpt_list').height(48);
        $('.ctrlBtn').css('bottom','-28px')
                    .find('i')
                    .removeClass('fa-angle-up')
                    .addClass('fa-angle-down')
                    .end()
                    .find('span')
                    .text('更多');
    } else {
        $('.courseOpt_list').height(68);
        $('.ctrlBtn').css('bottom','-28px')
                    .find('i')
                    .removeClass('fa-angle-up')
                    .addClass('fa-angle-down')
                    .end()
                    .find('span')
                    .text('更多');
    };



/*获取链接参数*/
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
};


//获取页面视口宽高
function getViewRect() {
    var pageWidth = window.innerWidth
        ,pageHeight = window.innerHeight;

    if ( typeof pageWidth != 'number' ) {
        if ( document.compatMode == 'CSS1Compat') {
            pageWidth = document.documentElement.clientWidth;
            pageHeight = document.documentElement.clientHeight;
        } else {
            pageWidth = document.body.clientWidth;
            pageHeight = document.body.clientHeight;
        }
    }
    return {
        width: pageWidth,
        height: pageHeight
    };  
};


/*判断横竖屏*/
function hengshuping(){ 
  if(window.orientation==180||window.orientation==0){ 
        var h = getViewRect().height;
        $('html').css('minHeight',h + 'px');    
   } 
  if(window.orientation==90||window.orientation==-90){ 
        var h = getViewRect().height;
        $('html').css('minHeight',h + 'px');          
    } 
};

if(mob == 'true') {
    $(window).on('orientationchange',function() {
        setTimeout(function() {
            hengshuping();
        },600);         
    }); 
};


var browser = {
versions: function() {
var u = navigator.userAgent, app = navigator.appVersion;
return {//移动终端浏览器版本信息 
trident: u.indexOf('Trident') > -1, //IE内核
presto: u.indexOf('Presto') > -1, //opera内核
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
iPad: u.indexOf('iPad') > -1, //是否iPad
webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部
};
}(),
language: (navigator.browserLanguage || navigator.language).toLowerCase()
}

var ua = window.navigator.userAgent.toLowerCase();

if(ua.match(/MicroMessenger/i) == 'micromessenger'){
    $('.wholePage').show();
}else if(browser.versions.ios || browser.versions.iPhone || browser.versions.iPad){
    //$('#downMsg').show();
    location.href = 'https://www.geekf.org';
}else{
    //$('#downMsg').show();
    location.href = "http://www.warsong.win";
}


</script>   
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值