判断浏览器客户端是不是移动客户端

1.C#
string osPat = "mozilla|m3gate|winwap|openwave|Windows NT|Windows 3.1|95|Blackcomb|98|ME|X Window|Longhorn|ubuntu|AIX|Linux|AmigaOS|BEOS|HP-UX|OpenBSD|FreeBSD|NetBSD|OS/2|OSF1|SUN";
string uAgent = Request.ServerVariables["HTTP_USER_AGENT"];
Regex reg = new Regex(osPat);
if (reg.IsMatch(uAgent))
{
    Response.Write("电脑访问");
}
else
{
    Response.Write("手机访问");
}
Response.Write("<br/>" + uAgent);


2.javascript

$(document).ready(function () {
//平台、设备和操作系统
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 = “http://www.offcn.com/zhuanti/2015gkyh/”;
} else {
window.location.href = “http://m.offcn.com/zhuanti/2015gkyh/”;//手机
}
});

你可能感兴趣的:(浏览器)