js获取设备信息


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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM