js判斷使用者裝置語法

有的時候我們會有PC版網頁及MB版網頁,若使用者用手機瀏覽時我們可用JS設定轉向至Mobile版

if (navigator.userAgent.match(/Android/i)
            || navigator.userAgent.match(/webOS/i)
            || navigator.userAgent.match(/iPhone/i)
            || navigator.userAgent.match(/iPad/i)
            || navigator.userAgent.match(/iPod/i)
            || navigator.userAgent.match(/BlackBerry/i)
            || navigator.userAgent.match(/Windows Phone/i)
            ){
                window.location.href = 'mobile.html';
            }else{

            }

發表迴響