天天看點

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/" target="_blank" rel="external nofollow" }catch(e){}}

}

script>

Android  iPhone Windows Phone 等主流手機系統測試全部通過