您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

js判断是PC端还是移动端

2024/6/24 16:56:46发布52次查看
本文主要和大家分享js判断是pc端还是移动端的方法,希望能帮助到大家。
#### 方案1:" function ispc() { var useragentinfo = navigator.useragent; var agents = ["android", "iphone", "symbianos", "windows phone", "ipad", "ipod"]; var flag = true; for (var v = 0; v < agents.length; v++) { 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(); "
#### 方案3:
" var browser_class = navigator.useragent; var browser_class_name1 = browser_class.match("mobile"); var browser_class_name2 = browser_class.match("mobile"); var location_url = window.location.href; if (browser_class_name1 != null || browser_class_name2 != null) { if (location_url.match("wap") == null) { window.location.href = "http://wap.xxxx.com"; } } else { if (location_url.match("3g") != null || location_url.match("wap") != null) { window.location.href = "http://wap.xxxx.com"; } } "
#### 百度方案:
" function uaredirect(f) { try { if (document.getelementbyid("bdmark") != null) { return } var b = false; if (arguments[1]) { var e = window.location.host; var a = window.location.href; 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 = window.location.hash; if (!c.match("fromapp")) { if ((navigator.useragent.match(/(iphone|ipod|android|ios|symbianos)/i))) { location.replace(f) } } } } catch(d) {} } function issubdomain(c, d) { this.getdomain = function(f) { var e = f.indexof("://"); if (e > 0) { var h = f.substr(e + 3) } else { var h = f } var g = /^www\./; if (g.test(h)) { h = h.substr(4) } return h }; if (c == d) { return 1 } else { var c = this.getdomain(c); var b = this.getdomain(d); if (c == b) { return 1 } else { c = c.replace(".", "\\."); var a = new regexp("\\." + c + "$"); if (b.match(a)) { return 2 } else { return 0 } } } }; "
使用方法:
" <script type=text/javascript>uaredirect("手机站","web站");</script> "
#### 类似方案:
" //判断访问的设备信息 var ua = window.navigator.useragent.tolowercase(); if (ua.indexof('android') != -1) { window.location = path + "/downloadsoftware/" + name + "/" + id+ "/"; } else if (ua.indexof('iphone') != -1 || ua.indexof('ipad') != -1) { window.top.location = "苹果官网"; } else if (ua.indexof("window nt")) { window.top.location = path + "/"; } else { alert("sorry,暂不支持您的系统下载!!"); } "
设备信息:
> mac:
>
> mozilla/5.0 (macintosh; intel mac os x 10_11_6) applewebkit/604.4.7 (khtml, like gecko) version/11.0.2 safari/604.4.7
>
> windows:
>
> mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/62.0.3202.94 safari/537.36
>
> ipad:
>
> mozilla/5.0 (ipad; cpu os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko) version/9.0 mobile/13b143 safari/601.1
>
> iphone:
>
> mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko) version/9.0 mobile/13b143 safari/601.1
>
> android:
>
> mozilla/5.0 (linux; android 5.0; sm-g900p build/lrx21t) applewebkit/537.36 (khtml, like gecko) chrome/62.0.3202.94 mobile safari/537.36
>
相关推荐:
php如何判断是否为手机端
php判断手机端、pc端 、微信示例代码分享
js判断手机端(android手机还是iphone手机)_javascript技巧
以上就是js判断是pc端还是移动端的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product