比如有些语句想在桌面浏览器下执行,但不希望手机浏览器执行,有什么办法?
业精于勤,荒于嬉;行成于思,毁于随。
参考: http://segmentfault.com/q/1010000000227004#a-1020000000267632
整理于网络:
//判断是否是手机访问; var ua = navigator.userAgent; var ipad = ua.match(/(iPad).*OSs([d_]+)/), isIphone = !ipad && ua.match(/(iPhonesOS)s([d_]+)/), isAndroid = ua.match(/(Android)s+([d.]+)/), isMobile = isIphone || isAndroid, isWeiXin = ua.match(/MicroMessenger/); if(isMobile || isWeiXin) { }else{ }
判断ua
navigator.userAgent返回的有一项是操作系统
navigator.userAgent
navigator.userAgent.toLowerCase().indexOf('mobile') > -1
var ua = window.navigator.userAgent.toLowerCase(); if (ua.indexOf('android') != -1) { location.replace('android.html'); } else if (ua.indexOf('iphone') != -1) { location.replace('iphone.html'); }else{ location.replace('pc.html'); }
参考: http://segmentfault.com/q/1010000000227004#a-1020000000267632
整理于网络:
判断ua
navigator.userAgent
返回的有一项是操作系统navigator.userAgent.toLowerCase().indexOf('mobile') > -1