h5页面判断安卓或ios点击下载App

h5页面判断安卓或ios点击下载

<input type="button" class="btn download-app" value="下载App" onclick="downApp()">

//判断访问终端
function downApp(){
    var u = navigator.userAgent,
        isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1,
        isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
        urls = {
            'android':'http://192.168.0.10:9080/static-uploads/public/2017-11/1-20171113-144142127.apk',
            'ios':'https://itunes.apple.com/cn/app/%E4%B8%89%E5%86%9C%E5%80%9F%E6%AC%BE/id1284453273?mt=8'
        };
    //三元运算
    // window.location.href = isAndroid? urls.android : isiOS? urls.ios : urls.other;
    //简化
    if(isAndroid){
        window.location.href=urls.android;
    }else if(isiOS){
        window.location.href=urls.ios;
    }
}
downApp();

你可能感兴趣的:(其他)