var su = navigator.userAgent.toLowerCase(), mb = ['ipad', 'iphone os', 'midp', 'rv:1.2.3.4', 'ucweb', 'android', 'windows ce', 'windows mobile']; // su為設備信息,大家可以輸出看下內容 document.getElementById("device").innerHTML = su; // 開始遍歷提前設定好的設備關鍵字,如果設備信息中包含關鍵字,則說明是該設備 for (var i in mb) { if (su.indexOf(mb[i]) > 0) { document.getElementById("tip").innerHTML = "this is " + mb[i] + " devices"; return; } } // 如果遍歷結束還沒有匹配到的則說明是pc端訪問 document.getElementById("tip").innerHTML = "this is pc devices";