欢迎您访问我爱IT技术网,今天小编为你分享的电脑教程是站长建站系列之:【ASP如何判断客户端是手机还是电脑,然后自动跳转?】,下面是详细的分享!
ASP如何判断客户端是手机还是电脑,然后自动跳转?
查看 环境变量里面的 http 响应类型 HTTP_ACCEPT 是否有 wap的信息
<%
if InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/vnd.wap.wml")>0 then
response.redirect "wap.asp" '如果是手机访问则跳转到wap.asp
else
response.redirect "index.asp" '如果电脑访问跳转到首页
end if
response.end
%>
代码二<%If InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/vnd.wap.wml") > 0 Then Response.Redirect "wap.asp"%>
三
<% If InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/vnd.wap.wml") > 0 Then Response.Redirect "big5/index.htm" Elseif InStr(LCase(Request.ServerVariables("HTTP_USER_AGENT")),"iphone") > 0 Then Response.Redirect "big5/index.htm" else Response.Redirect "index.html" end if%>
或者根据下面这个改,原理如下:
<%
if instr(request.servervariables("http_user_agent"),"Mobile")>0 then
'手机
else
'PC
end if
%>
限于条件,以上代码我只测试了Android系统手机和平板电脑,如果是苹果、塞班、黑莓等其他系统的智能手机,你可以自己测试,方法是新建一个ASP文件,内容只有一行:
<%=request.servervariables("http_user_agent")%>
然后放到你的网站上,然后用手机上的浏览器打开,看显示出来的文字中有什么特征字串,然后把它作为判断条件即可。
总的移动端代码如下,如果还要细分IOS、安卓、WP就再细分一下,代码如下:
通过 HTTP_USER_AGENT 判断区分
对ios、安卓、wp 你再归类区分一下
set regex=new regexp
regex.ignorecase=true
regex.global=true
regex.pattern="mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile|ipod|iphone|android|opera mini|blackberry|palm os|palm|hiptop|avantgo|fennec|plucker|xiino|blazer|elaine|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile"
agent=request.ServerVariables("HTTP_USER_AGENT") & ""
if agent <> "" then
if regex.test(agent) then
response.write "是从手机"
else
response.write "不是从手机"
end if
end if
以上就是关于ASP如何判断客户端是手机还是电脑,然后自动跳转?的手机问答知识分享,更多电脑教程请移步到>>电脑教程频道。
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
