js如何判断是手机端还是PC端访问
Posted Fly , Mason ! ! !
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js如何判断是手机端还是PC端访问相关的知识,希望对你有一定的参考价值。
function isMobile(){
var sUserAgent= navigator.userAgent.toLowerCase(),
bIsIpad= sUserAgent.match(/ipad/i) == "ipad",
bIsIphoneOs= sUserAgent.match(/iphone os/i) == "iphone os",
bIsMidp= sUserAgent.match(/midp/i) == "midp",
bIsUc7= sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4",
bIsUc= sUserAgent.match(/ucweb/i) == "ucweb",
bIsandroid= sUserAgent.match(/android/i) == "android",
bIsCE= sUserAgent.match(/windows ce/i) == "windows ce",
bIsWM= sUserAgent.match(/windows mobile/i) == "windows mobile",
bIsWebview = sUserAgent.match(/webview/i) == "webview";
return (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM);
}
function isMobile02(){
//平台、设备和操作系统
var system = {
win: false,
mac: false,
xll: false
};
//检测平台
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
//跳转语句
if (system.win || system.mac || system.xll) {//转向后台登陆页面
//window.location.href = "index.html";
return false;
} else {
return ture;
//window.location.href = "HomeIndex.aspx";//手机
}
}
以上是关于js如何判断是手机端还是PC端访问的主要内容,如果未能解决你的问题,请参考以下文章