ASP检测手机客户端并跳转到相应页面

该博客介绍了如何使用ASP技术检测访问者是否来自手机客户端,并根据检测结果自动跳转到相应的WAP页面,提供了详细的步骤和正则表达式参考链接。
<%
Function CheckMobile()

	'是否由wap转入电脑版
	If  Not IsEmpty(Request.ServerVariables("HTTP_REFERER"))  And  InStr(LCase(Request.ServerVariables("HTTP_REFERER")),"wap/index.asp")=0 Then 
			CheckMobile=False:Exit Function  
	End If 

	'是否专用wap浏览器
	If InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")), "application/vnd.wap.xhtml+xml") Or Not IsEmpty(Request.ServerVariables("HTTP_X_PROFILE")) Or Not IsEmpty(Request.ServerVariables("HTTP_PROFILE")) Then
			CheckMobile=True:Exit Function
	End If 

	'是否(智能)手机浏览器
	Dim MobileBrowser_List,PCBrowser_List,UserAgent
	Set MobileBrowser_List = New RegExp '建立正则表达式
	Set PCBrowser_List = New RegExp '建立正则表达式
	MobileBrowser_List.Pattern ="up.browser|up.link|mmp|iphone|android|wap|netfront|java|opera\smini|ucweb|windows\sce|symbian|series|webos|sonyericsson|sony|blackberry|cellphone|dopod|nokia|samsung|palmsource|palmos|pda|xphone|xda|smartphone|pieplus|meizu|midp|cldc|brew|tear"
	PCBrowser_List.Pattern="mozilla|chrome|safari|opera|m3gate|winwap|openwave"
	UserAgent = LCase(Request.ServerVariables("HTTP_USER_AGENT"))
	
	If MobileBrowser_List.Test(UserAgent) Then
		CheckMobile=True:Exit Function
	ElseIf PCBrowser_List.Test(UserAgent) Then '未知手机浏览器,其UA标识为常见浏览器,不跳转
		CheckMobile=False:Exit Function
	Else 
		CheckMobile=False 
	End If 

End Function 

If CheckMobile() Then 
	Response.Redirect ("wap/index.asp")
end if
%>

<%
	if InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/vnd.wap.wml")>0 then
		response.redirect("wap/index.asp") '如果是手机访问则跳转WAP页面
	else
		response.redirect("index.html")
	end if
%>

【详细说明

跳转http://zhidao.baidu.com/question/329884999.html

正则表达式http://www.jb51.net/article/20816.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值