function fBrowserRedirect(){
var sUserAgent=navigator.userAgent.toLowerCase()
var bIsIpad=sUserAgent.match(/ipad/i)=="ipad"
var bIsIphoneOs=sUserAgent.match(/iphone os/i)=="iphone os"
var bIsMidp=sUserAgent.match(/midp/i)=="midp"
var bIsUc7=sUserAgent.match(/rv:1.2.3.4/i)=="rv:1.2.3.4"
var bIsUc=sUserAgent.match(/ucweb/i)=="ucweb"
var bIsAndroid=sUserAgent.match(/android/i)=="android"
var bIsCE=sUserAgent.match(/windows ce/i)=="windows ce"
var bIsWM=sUserAgent.match(/windows mobile/i)=="windows mobile"
if(bIsIpad||bIsIphoneOs||bIsAndroid||bIsMidp||bIsUc7||bIsUc||bIsCE||bIsWM
{
alert("手机客户端")
if(!bForcepc){
alert("手机客户端")
}
}
}
function fGetQuery(name){
var sUrl=window.location.search.substr(1)
var r = sUrl.match(new RegExp("(^|&)"+name+"=([^&]*)(&|$)"))
return (r==null ? null : unescape(r[2]))
}
1、第一种:复制代码 代码如下:
function IsPC() {
var userAgentInfo = navigator.userAgent
var Agents = ["Android", "iPhone",
"SymbianOS", "Windows Phone",
"iPad", "iPod"]
var flag = true
for (var v = 0v <Agents.lengthv++) {
if (userAgentInfo.indexOf(Agents[v]) >0) {
flag = false
break
}
}
return flag
}
2、第二种:
复制代码 代码如下:
function browserRedirect() {
var sUserAgent = navigator.userAgent.toLowerCase()
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"
var bIsMidp = sUserAgent.match(/midp/i) == "midp"
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"
var bIsAndroid = sUserAgent.match(/android/i) == "android"
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"
if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
window.location.href=B页面
}
}
browserRedirect()
1、通过判断浏览器的userAgent,用正则来判断是否是ios和Android客户端。代码如下:
2、检查是否是移动端(Mobile)、ipad、iphone、微信、QQ等:
使用方法:
检测浏览器语言:
3、判断iPhone|iPad|iPod|iOS|Android客户端:
4、判断pc还是移动端: