您好,欢迎访问一九零五行业门户网

JS如何判断移动端访问设备并解析对应CSS_javascript技巧

复制代码 代码如下:
// 判断是否为移动端运行环境
if(/applewebkit.*mobile/i.test(navigator.useragent) || (/midp|symbianos|nokia|samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|philips|haier|lenovo|mot-|nokia|sonyericsson|sie-|amoi|zte/.test(navigator.useragent))){
if(window.location.href.indexof(?mobile)try{
if(/android|webos|iphone|ipod|blackberry/i.test(navigator.useragent)){
// 判断访问环境是 android|webos|iphone|ipod|blackberry 则加载以下样式
setactivestylesheet(style_mobile_a.css);
}
else if(/ipad/i.test(navigator.useragent)){
// 判断访问环境是 ipad 则加载以下样式
setactivestylesheet(style_mobile_ipad.css);
}
else{
// 判断访问环境是 其他移动设备 则加载以下样式
setactivestylesheet(style_mobile_other.css);
}
}
catch(e){}
}
}
else{
// 如果以上都不是,则加载以下样式
setactivestylesheet(style_mobile_no.css);
}
// 判断完毕后加载样式
function setactivestylesheet(filename){document.write();}
其它类似信息

推荐信息