jquery - 如何针对手机浏览器和桌面浏览器分别执行不同的 javascript 语句?
迷茫
迷茫 2017-04-10 12:47:22
0
5
547

比如有些语句想在桌面浏览器下执行,但不希望手机浏览器执行,有什么办法?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(5)
Peter_Zhu

参考: 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.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');
    }

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template