2021-02-09js判断手机是安卓还是ios

/**
 * @name 判断iOS
 */
export const isiOS = ()=>{
    let u = navigator.userAgent;
    let iOs = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端\
    return iOs;
}
/**
 * @name 判断android
 */
export const isAndroid = ()=>{
    let u = navigator.userAgent;
    let android = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    return android
}
简写:
appDown() {
    var u = navigator.userAgent;
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    if(isiOS){
        window.location.href = 'ios下载地址'
    }else if(isAndroid){
        window.location.href = '安卓下载地址'
    }
}

你可能感兴趣的:(2021-02-09js判断手机是安卓还是ios)