1. 程式人生 > >Js判斷瀏覽器是否是移動裝置

Js判斷瀏覽器是否是移動裝置

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

<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>