现在我们在制作网页的时候,为了提高用户体验,有时候会需要先判断用户是用电脑访问还是手机访问,下面分享一下ASP代码:
- <%
- '判断是否是手机上网
- 'response.write Request.ServerVariables("HTTP_ACCEPT")&"<BR>"
- 'response.write Request.ServerVariables("HTTP_USER_AGENT")&"<BR>"
- URL="http://www.iscripts.org/?mobile=yes"
- If Request.ServerVariables("HTTP_X_WAP_PROFILE") Then '如果有HTTP_X_WAP_PROFILE则是手机
- ' response.write "手机用户1"
- response.redirect URL
- response.End
- End If
- '如果只支持wml并且不支持html则是手机
- If InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml") > 0 And InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html")=0 Then
- ' Response.write "手机用户2"
- response.redirect URL
- response.End
- End If
- '如果支持wml和html但是wml在html之前则是移动设备
- If InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml") And InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html") Then
- If InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml")< InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html") Then
- ' Response.write "手机用户3"
- response.redirect URL
- respone.End
- End If
- End If
- '如果手机User_Agent有品牌特征符则是手机
- Set reg = New RegExp
- str="CECT,Compal,CTL,LG,NEC,TCL,Alcatel,Ericsson,BIRD,DAXIAN,DBTEL,Eastcom,PANTECH,Dopod,PHILIPS,HAIER,KONKA,KEJIAN,LENOVO,BenQ,MOT,Soutec,Nokia,SAGEM,SGH,SED,Capitel,Panasonic,SonyEricsson,SIE,SHARP,Amoi,PANDA,ZTE"
- str=Replace(str,",",")|(")
- reg.pattern=".*("&str&").*"
- reg.IgnoreCase = True
- response.write str&"<BR>"®.pattern
- If reg.test(Request.ServerVariables("HTTP_USER_AGENT")) Then
- ' response.write "手机用户4"
- response.redirect URL
- respone.End
- End If
- %>
第1页 第2页