【函数封装】javascript判断移动端操作系统为android 或 ios 或 iphoneX
function isPhone(){ 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终端 var isIphoneX = /iphone/gi.test(navigator.userAgent) && (screen.height == 812 && screen.width == 375); if (isAndroid) { return 1;//安卓操作系统 }else if (isIOS && !isIphoneX) { return 2;//ios操作系统 }else if(isIOS && isIphoneX){ return 3; //iphoneX机型 } }