Js判断浏览器是否是移动设备

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dengmengxin/article/details/50630571

可能有其它缺陷,不过正常能用

<script type="text/javascript">
function detectMobile() {
    return navigator.userAgent.match(/Android/i)
                    || navigator.userAgent.match(/webOS/i)
                    || navigator.userAgent.match(/iPhone/i)
                    || navigator.userAgent.match(/BlackBerry/i)
                    || navigator.userAgent.match(/Windows Phone/i);
}


if (navigator.userAgent.match(/iPad/i)) {
   //iPad设备
}


if (detectMobile()) {
   //移动设备
}else{
   //PC
}
</script>

猜你喜欢

转载自blog.csdn.net/dengmengxin/article/details/50630571