<% set regex = new regexp regex.ignorecase = true regex.global = true regex.pattern = "iemobile|iphone|ipod|android|nokia|sonyericsson|blackberry|samsung|sec\-|windows ce|motorola|mot\-|up.b|midp\-" agent = request.ServerVariables("HTTP_USER_AGENT") & "" if agent <> "" then if not regex.test(agent) then '不是从手机来的访问,跳转到7days/index.asp response.redirect("7days/index.asp") else response.redirect "index.aspx" '如果是手机访问则跳转WAP页面 end if end if %>
最简单的方法: 分辨率 高度 》 宽度 的是手机 if(window.screen.heigh > window.screen.width){ alert("手机"); } 另外就是 navigator.userAgent 和 navigator.platform 来判断贴一些userAgent:傲游浏览器: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; Maxthon 2.0)IE 而IE各个版本典型的userAgent如下: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2) Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Mozilla/4.0 (compatible; MSIE 5.0; Windows NT) 其中,版本号是MSIE之后的数字。Firefox Firefox几个版本的userAgent大致如下: Mozilla/5.0 (Windows; U; Windows NT 5.2) Gecko/2008070208 Firefox/3.0.1 Mozilla/5.0 (Windows; U; Windows NT 5.1) Gecko/20070309 Firefox/2.0.0.3 Mozilla/5.0 (Windows; U; Windows NT 5.1) Gecko/20070803 Firefox/1.5.0.12 其中,版本号是Firefox之后的数字。Opera Opera典型的userAgent如下: Opera/9.27 (Windows NT 5.2; U; zh-cn) Opera/8.0 (Macintosh; PPC Mac OS X; U; en) Mozilla/5.0 (Macintosh; PPC Mac OS X; U; en) Opera 8.0 其中,版本号是靠近Opera的数字。Safari Safari典型的userAgent如下: Mozilla/5.0 (Windows; U; Windows NT 5.2) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13 Mozilla/5.0 (iPhone; U; CPU like Mac OS X) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A93 Safari/419.3 其版本号是Version之后的数字。Chrome 目前,Chrome的userAgent是: Mozilla/5.0 (Windows; U; Windows NT 5.2) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13 其中,版本号在Chrome之后的数字。Navigator 目前,Navigator的userAgent是: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080219 Firefox/2.0.0.12 Navigator/9.0.0.6 其中,版本号在Navigator之后的数字。iPhone平台浏览器系列: iPhone自带safari: 特征表现:以"mozilla/"开头,含有"iphone"字符串,同时含有 "mobile/","safari/"字符串; 判断方法:粗略判断只检索 "iphone"和"safari/"字符串,严格判断则要同时包含 "mozilla/","iphone","mobile/","safari/"四个字符串 iPhone版Opera Mobile: 特征表现: 以"opera/"开头,含有"iphone"字符串,同时含有 "opera mini/","presto/"字符串; 判断方法:粗略判断只检索 "iphone"和"opera/"字符串,严格判断则要同时包含 "opera/","iphone","opera mini/","presto/"四个字符串 小结:iPhone手机上的浏览器userAgent均包含"iphone"字符串 Android平台浏览器系列: Android自带浏览器(有人说其实是就chrome,但google自己未做表示,且还在开发一个Android上运行的Chrome to Phone): 特征表现: 以"mozilla/"开头,含有"android"和"linux" 字符串,同时含有 "applewebkit/","mobile safari/"字符串; 判断方法:因为还不知道Android上未来会不会有独立的safari(估计不会了),所以建议直接严格判断,检索 "mozilla/","android","linux","applewebkit/","mobile safari/"五个字符串 Android版Opera Mobile: 特征表现: 以"opera/"开头,含有"android"和"linux" 字符串,同时含有 "opera mobi/","presto/"字符串; 判断方法:粗略判断只检索 "android"和"opera/",严格判断则要同时包含"opera/","android","linux","opera mobi/","presto/"五个字符串 Android版Firefox: 特征表现:以"mozilla/"开头,含有"android"和"linux" 字符串,同时含有 "firefox/","gecko/","fennec/"字符串; 判断方法:粗略判断只检索 "android"和"firefox/",严格判断则要同时包含"mozilla/","android","linux","firefox/","gecko/","fennec/"六个字符串 小结:Android平台上的浏览器userAgent均包含"android"和"linux"字符串目前手机浏览器中比较火的是 UC浏览器, 它的useragent 有一个特点。肯定是包含 UCWEB 这个字眼。 UC浏览器:NokiaE71/UCBrowser7.7.0.81/28/800 QQ 手机浏览器 TTMobile/09.03.18/symbianOS9.1 Series60/3.0 Nokia6120cAP3.03 用QQ浏览器:E71-1/SymbianOS/9.1 Series60/3.0 opera mini: Opera/9.80 (Series 60; Opera Mini/6.24095/25.718; U; zh) Presto/2.5.25 Version/10.54 下面搜集的一些Agent,话说找到这么多的智能设备,好不容易啊:Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_2 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5MQQBrowser/25 (Linux; U; 2.3.3; zh-cn; HTC Desire S Build/GRI40;480*800)Mozilla/5.0 (Linux; U; Android 2.3.3; zh-cn; HTC_DesireS_S510e Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaE75-1 /110.48.125 Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8J2 Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/7534.48.3Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/7534.48.3Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/7534.48.3 Mozilla/5.0 (Windows NT 5.2) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; OMNIA7) —-SAMSUNG MP7Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; XBLWP7; ZuneWP7) —-HTC MP7 手机浏览器总结:包括:iphone,android,mini,mobile,mobi,Nokia,Symbian, "iPod", "iPad", "Windows Phone", "MQQBrowser",wp7,UCBrowser7,UCBrowser7,UCWEB
获取客户端电脑IP:Page.Request.UserHostAddress
哪个能用用哪个, 如果有电脑名或者IP,就是电脑, 否则就是手机
{
HttpCapabilitiesBase r = (System.Web.Configuration.HttpCapabilitiesBase)Request.Browser;
string agent = (Request.UserAgent + "").ToLower().Trim();
LogResult(
"IsMobileDevice--" + r.IsMobileDevice + "\r\n" +
"HtmlTextWriter--" + r.HtmlTextWriter + "\r\n" +
"CanRenderPostBackCards--" + r.CanRenderPostBackCards + "\r\n" +
"Browser--" + r.Browser + "\r\n" +
"Type--" + r.Type + "\r\n" +
"SupportsJPhoneSymbols--" + r.SupportsJPhoneSymbols + "\r\n" +
"SupportsIModeSymbols--" + r.SupportsIModeSymbols + "\r\n" +
"RequiresPhoneNumbersAsPlainText--" + r.RequiresPhoneNumbersAsPlainText + "\r\n" +
"PreferredRequestEncoding--" + r.PreferredRequestEncoding + "\r\n" +
"PreferredRenderingType--" + r.PreferredRenderingType + "\r\n" +
"IsMobileDevice--" + r.IsMobileDevice + "\r\n" +
"ClrVersion--" + r.ClrVersion + "\r\n" +
"Request.UserAgent--" + agent + "\r\n" +
"agent.IndexOf(\"mozilla\")--" + agent.IndexOf("mozilla") + "\r\n" +
"agent.IndexOf(\"opera\")--" + agent.IndexOf("opera")
);
if (r.IsMobileDevice)
{
Response.Write("mobile");
}
else
{
Response.Write("www");
}
}听说回切是种美的
<%
set regex = new regexp
regex.ignorecase = true
regex.global = true
regex.pattern = "iemobile|iphone|ipod|android|nokia|sonyericsson|blackberry|samsung|sec\-|windows ce|motorola|mot\-|up.b|midp\-" agent = request.ServerVariables("HTTP_USER_AGENT") & ""
if agent <> "" then
if not regex.test(agent) then
'不是从手机来的访问,跳转到7days/index.asp
response.redirect("7days/index.asp")
else
response.redirect "index.aspx" '如果是手机访问则跳转WAP页面
end if
end if %>
我试的可以成功,
[code=C#] if (HttpContext.Current.Request.Headers["user-agent"] != null && HttpContext.Current.Request.Headers["user-agent"].ToLower().ToString().IndexOf("mozilla") != -1)
{
HttpContext.Current.Response.Redirect("./Home/"); //PC
}
else
{
HttpContext.Current.Response.Redirect("./scm/wap/login.aspx"); //Mobile ClientTypeTesting.
}code]
if (HttpContext.Current.Request.Headers["user-agent"] != null && HttpContext.Current.Request.Headers["user-agent"].ToLower().ToString().IndexOf("mozilla") != -1)
{
HttpContext.Current.Response.Redirect("./Home/"); //PC
}
else
{
HttpContext.Current.Response.Redirect("./scm/wap/login.aspx"); //Mobile ClientTypeTesting.
}
下面是方法
public static Boolean choose(String userAgent)
{
if (userAgent.IndexOf("Noki") > -1 || // Nokia phones and emulators
userAgent.IndexOf("Eric") > -1 || // Ericsson WAP phones and emulators
userAgent.IndexOf("WapI") > -1 || // Ericsson WapIDE 2.0
userAgent.IndexOf("MC21") > -1 || // Ericsson MC218
userAgent.IndexOf("AUR") > -1 || // Ericsson R320
userAgent.IndexOf("R380") > -1 || // Ericsson R380
userAgent.IndexOf("UP.B") > -1 || // UP.Browser
userAgent.IndexOf("WinW") > -1 || // WinWAP browser
userAgent.IndexOf("UPG1") > -1 || // UP.SDK 4.0
userAgent.IndexOf("upsi") > -1 || //another kind of UP.Browser
userAgent.IndexOf("QWAP") > -1 || // unknown QWAPPER browser
userAgent.IndexOf("Jigs") > -1 || // unknown JigSaw browser
userAgent.IndexOf("Java") > -1 || // unknown Java based browser
userAgent.IndexOf("Alca") > -1 || // unknown Alcatel-BE3 browser (UP based)
userAgent.IndexOf("MITS") > -1 || // unknown Mitsubishi browser
userAgent.IndexOf("MOT-") > -1 || // unknown browser (UP based)
userAgent.IndexOf("My S") > -1 ||// unknown Ericsson devkit browser
userAgent.IndexOf("WAPJ") > -1 ||//Virtual WAPJAG www.wapjag.de
userAgent.IndexOf("fetc") > -1 ||//fetchpage.cgi Perl script from www.wapcab.de
userAgent.IndexOf("ALAV") > -1 || //yet another unknown UP based browser
userAgent.IndexOf("Wapa") > -1 || //another unknown browser (Web based "Wapalyzer")
userAgent.IndexOf("Oper") > -1)
{
return true;
}
else
{
return false;
}
}
if(request.Contains("Windows NT")) 表示是电脑的
分辨率 高度 》 宽度 的是手机 if(window.screen.heigh > window.screen.width){
alert("手机");
}
另外就是
navigator.userAgent 和 navigator.platform 来判断贴一些userAgent:傲游浏览器:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; Maxthon 2.0)IE
而IE各个版本典型的userAgent如下:
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 5.0; Windows NT)
其中,版本号是MSIE之后的数字。Firefox
Firefox几个版本的userAgent大致如下:
Mozilla/5.0 (Windows; U; Windows NT 5.2) Gecko/2008070208 Firefox/3.0.1
Mozilla/5.0 (Windows; U; Windows NT 5.1) Gecko/20070309 Firefox/2.0.0.3
Mozilla/5.0 (Windows; U; Windows NT 5.1) Gecko/20070803 Firefox/1.5.0.12 其中,版本号是Firefox之后的数字。Opera
Opera典型的userAgent如下:
Opera/9.27 (Windows NT 5.2; U; zh-cn)
Opera/8.0 (Macintosh; PPC Mac OS X; U; en)
Mozilla/5.0 (Macintosh; PPC Mac OS X; U; en) Opera 8.0
其中,版本号是靠近Opera的数字。Safari
Safari典型的userAgent如下:
Mozilla/5.0 (Windows; U; Windows NT 5.2) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13
Mozilla/5.0 (iPhone; U; CPU like Mac OS X) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A93 Safari/419.3
其版本号是Version之后的数字。Chrome
目前,Chrome的userAgent是:
Mozilla/5.0 (Windows; U; Windows NT 5.2) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13
其中,版本号在Chrome之后的数字。Navigator
目前,Navigator的userAgent是:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080219 Firefox/2.0.0.12 Navigator/9.0.0.6
其中,版本号在Navigator之后的数字。iPhone平台浏览器系列:
iPhone自带safari:
特征表现:以"mozilla/"开头,含有"iphone"字符串,同时含有 "mobile/","safari/"字符串;
判断方法:粗略判断只检索 "iphone"和"safari/"字符串,严格判断则要同时包含 "mozilla/","iphone","mobile/","safari/"四个字符串
iPhone版Opera Mobile:
特征表现: 以"opera/"开头,含有"iphone"字符串,同时含有 "opera mini/","presto/"字符串;
判断方法:粗略判断只检索 "iphone"和"opera/"字符串,严格判断则要同时包含 "opera/","iphone","opera mini/","presto/"四个字符串
小结:iPhone手机上的浏览器userAgent均包含"iphone"字符串
Android平台浏览器系列:
Android自带浏览器(有人说其实是就chrome,但google自己未做表示,且还在开发一个Android上运行的Chrome to Phone):
特征表现: 以"mozilla/"开头,含有"android"和"linux" 字符串,同时含有 "applewebkit/","mobile safari/"字符串;
判断方法:因为还不知道Android上未来会不会有独立的safari(估计不会了),所以建议直接严格判断,检索 "mozilla/","android","linux","applewebkit/","mobile safari/"五个字符串
Android版Opera Mobile:
特征表现: 以"opera/"开头,含有"android"和"linux" 字符串,同时含有 "opera mobi/","presto/"字符串;
判断方法:粗略判断只检索 "android"和"opera/",严格判断则要同时包含"opera/","android","linux","opera mobi/","presto/"五个字符串
Android版Firefox:
特征表现:以"mozilla/"开头,含有"android"和"linux" 字符串,同时含有 "firefox/","gecko/","fennec/"字符串;
判断方法:粗略判断只检索 "android"和"firefox/",严格判断则要同时包含"mozilla/","android","linux","firefox/","gecko/","fennec/"六个字符串
小结:Android平台上的浏览器userAgent均包含"android"和"linux"字符串目前手机浏览器中比较火的是 UC浏览器,
它的useragent 有一个特点。肯定是包含 UCWEB 这个字眼。
UC浏览器:NokiaE71/UCBrowser7.7.0.81/28/800
QQ 手机浏览器
TTMobile/09.03.18/symbianOS9.1 Series60/3.0 Nokia6120cAP3.03
用QQ浏览器:E71-1/SymbianOS/9.1 Series60/3.0
opera mini:
Opera/9.80 (Series 60; Opera Mini/6.24095/25.718; U; zh) Presto/2.5.25 Version/10.54
下面搜集的一些Agent,话说找到这么多的智能设备,好不容易啊:Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_2 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5MQQBrowser/25 (Linux; U; 2.3.3; zh-cn; HTC Desire S Build/GRI40;480*800)Mozilla/5.0 (Linux; U; Android 2.3.3; zh-cn; HTC_DesireS_S510e Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaE75-1 /110.48.125 Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8J2
Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/7534.48.3Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/7534.48.3Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/7534.48.3
Mozilla/5.0 (Windows NT 5.2) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; OMNIA7) —-SAMSUNG MP7Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; XBLWP7; ZuneWP7) —-HTC MP7
手机浏览器总结:包括:iphone,android,mini,mobile,mobi,Nokia,Symbian,
"iPod", "iPad", "Windows Phone", "MQQBrowser",wp7,UCBrowser7,UCBrowser7,UCWEB