<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>

百度的判断代码

复制代码 代码如下:
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>

最新文章

  1. CSS Sprites优缺点
  2. APM的飞行模式
  3. C++基础——模拟事务 (1)COMMAND模式
  4. SpringMVC学习(一)
  5. NAT123 解决80端口被封的问题
  6. 每日一九度之 题目1030:毕业bg
  7. Java 日期 Api
  8. Map迭代器
  9. MAC中在eclipse luna上搭建移动平台自己主动化測试框架(UIAutomator/Appium/Robotium/MonkeyRunner)关键点记录
  10. 【算法】超大数组去重(Java语言实现)
  11. c#高级语言编程(第一部分)
  12. 在centos6编译安装http-2.4
  13. xshell连接centos与ubuntu
  14. 细说addEventListener与事件捕获
  15. Spring MVC 使用介绍(六)—— 注解式控制器(二):请求映射与参数绑定
  16. Java读写文件,字符输入流FileReader 和 字符输出流FileWriter
  17. Python3求解字符串滤值与百元买百鸡算法
  18. HDU 1425 C++使用sort函数
  19. MongoDB学习笔记(11) --- 聚合
  20. Linux 客户端bind函数的使用

热门文章

  1. lucene 异常 Lock obtain timed out 解决方法
  2. TCP/IP ---互联网的地址
  3. php 实现 html转js
  4. ucosii任务切换OS_TASK_SW()
  5. C# Enum,Int,String,之间及bool与int之间的转换
  6. SpringCloud系列九:脱离Eureka使用Ribbon
  7. python加密包
  8. PLSQL快捷键设置
  9. 虚拟化笔记04.OpenFiler.install
  10. 探讨把一个元素从它所在的div 拖动到另一个div内的实现方法