js 判断 微信浏览器 安卓/苹果 pc/移动

同页面在app和微信浏览器显示内容不同,android和ios用不同的下载链接 顺便附上pc/mobile

JS判断微信客户端

function isWeixin() {
    var ua = window.navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        return true;
    } else {
        return false;
    }
}

 

JS判断客户端环境(android/ios)

$(function () {
    var u = navigator.userAgent, app = navigator.appVersion;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
    var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    if (isAndroid) {
        window.location.href = 'appDownload.html';
    }
    if (isIOS) {
        window.location.href = 'iosDownload.html';
    }
});

 

JS判断是否为PC

function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["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;
}

 

posted on 2018-02-08 14:19  yanggg  阅读(395)  评论(0编辑  收藏  举报

导航