safari浏览器使用的事webkit内核,所以他们的标识是不同的,还有一种方式是手机用户浏览网站的时候会传递一个user-agent信息,里面包含手机的相关信息,这都可以用来识别,楼主如果想用电脑访问可以使用相关的模拟器,例如百度的wap模拟器等等。四种方法
function IsPC() {
var userAgentInfo = navigatoruserAgent;
var Agents = ["Android", "iPhone",
"SymbianOS", "Windows Phone",
"iPad", "iPod"];
var flag = true;
for (var v = 0; v < Agentslength; v++) {
if (userAgentInfoindexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}
function browserRedirect() {
var sUserAgent = navigatoruserAgenttoLowerCase();
var bIsIpad = sUserAgentmatch(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgentmatch(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgentmatch(/midp/i) == "midp";
var bIsUc7 = sUserAgentmatch(/rv:1234/i) == "rv:1234";
var bIsUc = sUserAgentmatch(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgentmatch(/android/i) == "android";
var bIsCE = sUserAgentmatch(/windows ce/i) == "windows ce";
var bIsWM = sUserAgentmatch(/windows mobile/i) == "windows mobile";
if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
windowlocationhref=B页面;
}
}
3正则匹配
var browser_class = navigatoruserAgent;
var browser_class_name1 = browser_classmatch("Mobile");
var browser_class_name2 = browser_classmatch("mobile");
var location_url = windowlocationhref;
if (browser_class_name1 != null || browser_class_name2 != null) {
if (location_urlmatch("wap") == null) {
windowlocationhref = "
}
} else {
if (location_urlmatch("3g") != null || location_urlmatch("wap") != null) {
windowlocationhref = "
}
}
4 百度判断
function uaredirect(f) {
try {
if (documentgetElementById("bdmark") != null) {
return
}
var b = false;
if (arguments[1]) {
var e = windowlocationhost;
var a = windowlocationhref;
if (isSubdomain(arguments[1], e) == 1) {
f = f + "/#m/" + a;
b = true
} else {
if (isSubdomain(arguments[1], e) == 2) {
f = f + "/#m/" + a;
b = true
} else {
f = a;
b = false
}
}
} else {
b = true
}
if (b) {
var c = windowlocationhash;
if (!cmatch("fromapp")) {
if ((navigatoruserAgentmatch(/(iPhone|iPod|Android|ios|SymbianOS)/i))) {
locationreplace(f)
}
}
}
} catch(d) {}
}
function isSubdomain(c, d) {
thisgetdomain = function(f) {
var e = findexOf("://");
if (e > 0) {
var h = fsubstr(e + 3)
} else {
var h = f
}
var g = /^>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)