以下代码用于JQuery判断访问的浏览器的类型
/**
* 判断访问类型是电脑还是手机
*
* @author 何明胜
*
* 2017年9月27日
*/
$(function(){
var mobile_flag = isMobile(); // true为PC端,false为手机端
if(mobile_flag){
$("#fh5co-main").css({"width": "100%", "float": "right"});
$("#trademark").css({"margin-left": "48px","margin-top": "16px"});
}
});
function isMobile() {
var userAgentInfo = navigator.userAgent;
var mobileAgents = [ "Android", "iPhone", "SymbianOS", "Windows Phone", "iPad","iPod"];
var mobile_flag = false;
//根据userAgent判断是否是手机
for (var v = 0; v < mobileAgents.length; v++) {
if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
mobile_flag = true;
break;
}
}
var screen_width = window.screen.width;
var screen_height = window.screen.height;
//根据屏幕分辨率判断是否是手机
if(screen_width < 500 && screen_height < 800){
mobile_flag = true;
}
return mobile_flag;
}
来源:oschina
链接:https://my.oschina.net/u/4272511/blog/4274627