asp判断是否移动端_asp程序判断是电脑PC端访问还是手机端访问的网页

asp程序判断是电脑PC端访问还是手机端访问的网页,可以通过以下功能来实现:

ASP中的Request.ServerVariables("HTTP_USER_AGENT") 用来识别登录客户端的。

经测试在各种手机中显示不一样,如下:

安卓:Mozilla/5.0 (Linux; U; Android 4.1.9; zh-cn; A908 Build/A908A908) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30

苹果iphone 4sMQQBrowser/35 Mozilla/5.0 (iPhone 4S; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206 Safari/7534.48.3

黑莓:Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; zh-CN) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.499 Mobile Safari/534.8+

比较共通的关键字是Mobile

asp版if instr(request.servervariables("http_user_agent"),"Mobile")>0 then

response.Write "手机"

else

response.Write "电脑"

end if

js版

if(/Android|webOS|iPhone|iPod|BlackBerry|Windows CE|Windows Phone/i.test(navigator.userAgent)){

if(window.location.href.indexOf("?pc")<0){try{window.location.href="http://www.xxxxx.com/wap/"}catch(e){}}

}

script>

Android  iPhone Windows Phone 等主流手机系统测试全部通过

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值