JS判断是手机访问还是PC端访问网站
<script>
if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i))) {
location.replace("http://m.helloweba.com")
}else{
document.write("请使用手机访问.");
}
</script>
百度的判断代码
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>
JS判断是手机访问还是PC端访问网站的更多相关文章
- js判断是手机端还是pc端访问
if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) { window.location.href = " ...
- JS判断当前使用设备是pc端还是web端(转MirageFireFox)
js判断当前设备 最近用bootstrap做自适应,发现仍然很难很好的兼容web端和PC端的现实. 仔细观察百度,淘宝,京东等大型网站,发现这些网站都有对应不同客户端的子站. 站点 PC端url we ...
- 【方法】JS判断当前页面环境:PC端/移动端,安卓/IOS,微信环境/QQ环境等等
[主要知识] 浏览器设备信息:navigator.userAgent(本文中主要用到知识) 浏览器版本信息:navigator.appVersion var ua = navigator.userAg ...
- js判断浏览器的环境(pc端,移动端,还是微信浏览器)
window.navigator.userAgent用来区分设备和浏览器 <!DOCTYPE html> <html> <head> <meta charse ...
- js如何判断是手机端还是PC端访问
function isMobile(){ var sUserAgent= navigator.userAgent.toLowerCase(), bIsIpad= sUserAgent.match(/i ...
- PHP判断是手机端访问还是PC端访问网站
Mobile_Detect 是一个轻量级的开源移动设备(手机)检测的 PHP Class, 它使用 User-Agent 中的字符串,并结合 HTTP Header,来检测移动设备环境. 这个设备检测 ...
- thinkphp中怎么判断是手机端访问还是pc端访问?
function isMobile() { // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) r ...
- JS判断设备类型跳转至PC端或移动端相应页面
if((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobil ...
- js判断设备是都是pc端
function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = new Array("Android" ...
随机推荐
- PHP-CURL在POST请求时的注意事项
今天搞12306抢票, 在用CURL模拟POST请求校验验证码时, 无论如何12306都返回零, 正常应该返回True或者False, 最后查找原因如下 只是请求头 Content-Type 用了 a ...
- 字符串算法之 AC自己主动机
近期一直在学习字符串之类的算法,感觉BF算法,尽管非常easy理解,可是easy超时,全部就想学习其它的一些字符串算法来提高一下,近期学习了一下AC自己主动机.尽管感觉有所收获,可是还是有些朦胧的感觉 ...
- 通过 P3P规范让IE跨域接受第三方cookie session
所谓第三方 cookie,就是说你访问网页 A,却接收到域名 B 的 cookie 设定指令.这可能是由于网页 A 请求或链接了 B 的网页,比如上面提到的 iframe 以及 jsonp. 我查到了 ...
- 自己动手开发更好用的markdown编辑器-07(扩展语法)
这里文章都是从个人的github博客直接复制过来的,排版可能有点乱. 原始地址 http://benq.im/2015/05/19/hexomd-07/ 文章目录 1. 准备工作 2. 目录语法 ...
- unity, change parent and keep localPosition or worlPosition
node.parent=othernode等价于node.setParent(othernode,true),是保持世界坐标不变. node.setParent(othernode,false)则可以 ...
- 26. Remove Duplicates from Sorted Array【easy】
26. Remove Duplicates from Sorted Array[easy] Given a sorted array, remove the duplicates in place s ...
- centos7系统备份与还原
1. 前言 在使用Ubuntu之前,相信很多人都有过使用Windows系统的经历.如果你备份过Windows系统,那么你一定记忆犹新:首先需要找到一个备份工具(通常都是私有软件),然后重启电脑进入备份 ...
- log4cxx日志库RedHat下安装
今天领导交给我一个任务:把log4cxx库在Redhat系统上面安装起来 首先.我得到信息,安装这个库一共须要三个软件 apr-1.4.6.tar.gz apr-util-1.4.1.tar.gz a ...
- mac下安装phpstorm主题
在<推荐一个phpstorm主题和字体>中介绍了window下如何安装phpstorm主题,这里我们在介绍一下如何在MAC下安装phpstorm主题. 安装方法和window类似,只是需要 ...
- archive的时候报“ no identity found"错误 解决方式
第一步: 在xcode----target----general----identity----team里 增加你们公司的账号就能够了 第二步: Xcode > Preferences > ...